| Author |
phone number regular expression problem
|
|
|
| Hi,
I have a different requirement and it is :
I need to validate a phone number field.
It may or may not be a US phone number.
The constraints are :
***********************
# It should accept any number of numbers
# any number of - hyphens
# and one + symbol
# no other characters and alphabets are allowed
Thanks in advance
Venugopal.S
| |
| David Squire 2006-05-31, 8:05 am |
| venu wrote:
> Hi,
> I have a different requirement and it is :
Different from what?
>
> I need to validate a phone number field.
> It may or may not be a US phone number.
>
> The constraints are :
> ***********************
>
> # It should accept any number of numbers
> # any number of - hyphens
> # and one + symbol
> # no other characters and alphabets are allowed
>
> Thanks in advance
Show us what you have tried, and folk here will help you to make it work.
DS
| |
| Jürgen Exner 2006-05-31, 8:05 am |
| venu wrote:
> I have a different requirement and it is :
>
> I need to validate a phone number field.
> It may or may not be a US phone number.
>
> The constraints are :
> ***********************
>
> # It should accept any number of numbers
> # any number of - hyphens
> # and one + symbol
> # no other characters and alphabets are allowed
No need to wield the big RE gun.
Step 1: use tr() with the 'c' and 'd' options to keep only desirable
characters in the string. If the string has changed, then you know it
contained at least one unwanted character.
Step 2: see FAQ entry "How can I count the number of occurrences of a
substring within a string?" for counting the number of '+' symbols. If it's
more than one then you got an illegal entry.
jue
| |
| Paul Lalli 2006-05-31, 8:05 am |
| venu wrote:
> I have a different requirement and it is :
>
> I need to validate a phone number field.
> It may or may not be a US phone number.
>
> The constraints are :
> ***********************
>
> # It should accept any number of numbers
> # any number of - hyphens
> # and one + symbol
> # no other characters and alphabets are allowed
>
> Thanks in advance
You forgot to post what salary you're offering for this project.
Paul Lalli
| |
| axel@white-eagle.invalid.uk 2006-05-31, 7:06 pm |
| venu <svenugopaal@gmail.com> wrote:
> I need to validate a phone number field.
> It may or may not be a US phone number.
> The constraints are :
> ***********************
> # It should accept any number of numbers
> # any number of - hyphens
> # and one + symbol
> # no other characters and alphabets are allowed
To check the constraints:
/^[0-9+-]*$/ && tr/+// < 2
I'm sure someone else can suggest a Perl module suitable for dialing
up the number in question to 'validate' it.
Axel
| |
| Glenn Jackman 2006-05-31, 7:06 pm |
| At 2006-05-31 09:24AM, venu <svenugopaal@gmail.com> wrote:
> Hi,
> I have a different requirement and it is :
>
> I need to validate a phone number field.
> It may or may not be a US phone number.
>
> The constraints are :
> ***********************
>
> # It should accept any number of numbers
> # any number of - hyphens
> # and one + symbol
> # no other characters and alphabets are allowed
http://search.cpan.org/~abigail/Reg...mmon/URI/tel.pm
--
Glenn Jackman
Ulterior Designer
|
|
|
|