hi i have validated a form with javascript, and now wish to do it it also with php, i have searched a few places and here but nothing comes up for what im after
PHP Code:
if ( $_GET["dob"] != 6 ) {
echo "Please Enter Your DOB In Format ddmmyy"
exit();
}
if ( $_GET["dob"] >= 311299 ) {
echo "Please Enter A Sensible DOB"
exit();
}
but these dont work, also if possible i want this field to only accept numbers, i guess using preg_match
i got it working fine with js, but as i am new or relativly new to php i cannot get this working, its my first form i have validated with, php
When you compare a string to a number, the string will always return as the numeric value of zero. String to number comparison won't work, you need to use strlen() instead.
To validate it, though, I'd suggest using this RegEx (untested, but should work):
PHP Code:
if(isset($_GET["dob"]))
{$dob = $_GET["dob"];}
if(!preg_match("/\d{6}/", $dob))
{die("You must enter a valid date format: MMDDYY.");}
[J]ona
Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.
ok thanks for the strlen function, i looked past that when reviewing the manual in search for how to do this
this code you gave me
if(isset($_GET["dob"]))
{$dob = $_GET["dob"];}
if(!preg_match("/d{6}/", $dob))
{die("You must enter a valid date format: MMDDYY.");}
returns "you must... mmddyy" whatever the value of dob is
im using this to check to see the strlen
$str = $_GET["dob"];
if(strlen($str) != 6) {
echo "Please enter your DOB in the format DDMMYY";
exit();
} else {
....
}
and this works fine, theres not a strval(), to check the value of a value, as i could do the same as my above code, but using strval() (or equivalent function) to make sure it is less that 311299, so what function would be capable of doing this? i have had a look at a couple of them but cant seem to find it
Rich
Last edited by 96turnerri; 03-29-2004 at 08:35 AM.
Bookmarks