Jump to content

Archived

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

feri_soft

need a validating function

Recommended Posts

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

Share this post


Link to post
Share on other sites
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:
[code]
<?php
$date = "15.12.06";
if (!preg_match('|[0-3][0-9]\.[0-1][0-9]\.[0-9]{2}|', $date)) {
  // invalid format
}
?>
[/code]

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

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.