Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple regex

Status
Not open for further replies.

johno77

Technical User
Nov 1, 2003
40
0
0
GB
Hi

I am creating a regex so that the variable telephone is a the value read in from a html form. I want to delete any white space which i think i have done and make sure there are eleven digits - while the script works for checking ranges 0-11 if the user enters fourteen numbers the prompt valid number appears

Any ideas

($telephone1 = $telephone) =~ s/\s+//g;
if ($telephone1=~m/\d{11}/){print &quot;$telephone is a valid option<br>&quot;;}
else {print &quot;$telephone is an invalid number<br>&quot;;}
 
If you want to specifically allow 0-11 digits, but no more you'd want
Code:
if ($telephone1=~m/^\d{0,11}$/)

I'm surprised that your previous code allowed less than 11 digits, though. It should have matched 11 digits anywhere in [tt]$telephone1[/tt].

In the new regex, the [tt]^[/tt] matches the beginning of the string and [tt]$[/tt] matches the end.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top