Jump to content

need a validating function


feri_soft

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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.