| Subject: | Re: Regular expression: How to determine wether entry is a number? |
|---|---|
| From: | paul@xxxxxxxx (Paul Johnson) |
| Date: | Tue, 29 Jul 2008 17:42:42 +0200 |
| Newsgroups: | perl.beginners |
On Tue, Jul 29, 2008 at 05:46:09AM -0700, Jan-Henrik wrote:
> Now I would like to check wether the user really entered a number and
> not letters. What would a check like that look like? A regular
> expression like this:
> ----------------------------------------
> unless ($foo =~ /[a-zA-Z\D+][^.][\D*]/ {...};
> ----------------------------------------
>
> Is there an easier or more beautiful way?
perldoc -q scalar number
> Also, how would I substract just a number from a string? Searched the
> net for an example but didn't succeed, so sorry for asking a question
> like that...
In general you might not have to, you can probably just use it as a number and
perl will do the right thing. But otherwise you could just put parentheses
around your regex to capture the numeric part.
--
Paul Johnson - paul@xxxxxxxx
http://www.pjcj.net
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: Regular expression: How to determine wether entry is a number?, Paul Lalli |
|---|---|
| Next by Date: | Re: Regular expression: How to determine wether entry is a number?, Jan-Henrik |
| Previous by Thread: | Re: Regular expression: How to determine wether entry is a number?, Jan-Henrik |
| Next by Thread: | Re: Regular expression: How to determine wether entry is a number?, Jan-Henrik |
| Indexes: | [Date] [Thread] [Top] [All Lists] |