feri_soft Posted August 30, 2006 Share Posted August 30, 2006 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.yycan 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 Quote Link to comment Share on other sites More sharing options...
obsidian Posted August 30, 2006 Share Posted August 30, 2006 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 9dotthird digit is between 0 and 1 (allows for 01-12)fourth digit is between 0 and 9 (allows for 01-12)dotlast 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.