Jump to content

Archived

This topic is now archived and is closed to further replies.

playaz

Form validation

Recommended Posts

Hi guys,

I just basically require a 'telephone' field on a form validated in the following way:

It only accepts whole numbers,
It allows for a space (eg 0161 123456)

Can anyone show me how this is done - thanks in advance. :)

Share this post


Link to post
Share on other sites
[!--quoteo(post=355312:date=Mar 15 2006, 06:54 AM:name=playaz)--][div class=\'quotetop\']QUOTE(playaz @ Mar 15 2006, 06:54 AM) [snapback]355312[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi guys,

I just basically require a 'telephone' field on a form validated in the following way:

It only accepts whole numbers,
It allows for a space (eg 0161 123456)

Can anyone show me how this is done - thanks in advance. :)
[/quote]

basically, here's a really simple regex that will check for a 10 digit number, but it will allow for a space after the fourth digit only:
[code]
if (preg_match("|^[0-9]{4}([ ]?)[0-9]{6}$|", $number))
  echo "Valid!<br />\n";
else
  echo "Invalid!<br />\n";
[/code]

hope this helps

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.