Jump to content


Photo

Form validation


  • Please log in to reply
2 replies to this topic

#1 playaz

playaz
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 15 March 2006 - 11:54 AM

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. :)

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 15 March 2006 - 01:17 PM

[!--quoteo(post=355312:date=Mar 15 2006, 06:54 AM:name=playaz)--][div class=\'quotetop\']QUOTE(playaz @ Mar 15 2006, 06:54 AM) View Post[/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:
if (preg_match("|^[0-9]{4}([ ]?)[0-9]{6}$|", $number))
  echo "Valid!<br />\n";
else
  echo "Invalid!<br />\n";

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 playaz

playaz
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 15 March 2006 - 04:20 PM

Thats perfect!

Thanks for taking time out to assist me :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users