Jump to content


Photo

need a validating function


  • Please log in to reply
1 reply to this topic

#1 feri_soft

feri_soft
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts

Posted 30 August 2006 - 04:19 PM

I cant figure it out hopw to make a function to validate the input of a text field.For example the text field have a date which must be formated

dd.mm.yy

can someone make this function or tell me how to do it.
So it could validate the field and if the input is not correct to return error msg...

Solution needed very much

#2 obsidian

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

Posted 30 August 2006 - 04:33 PM

if you're wanting to make sure that there is data in the specified format, you're best bet is to use a regular expression match. something like this should help:
<?php
$date = "15.12.06";
if (!preg_match('|[0-3][0-9]\.[0-1][0-9]\.[0-9]{2}|', $date)) {
  // invalid format
}
?>

this checks the following:
first digit is between 0 and 3 (allows for 01-31)
second digit is between 0 and 9
dot
third digit is between 0 and 1 (allows for 01-12)
fourth digit is between 0 and 9 (allows for 01-12)
dot
last two digits can be 0 through 9 (allows for 01-99)

this also helps make sure that only numbers have been entered.

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users