1
I had do some hack on edituser.php and function.php to do a validation for some fields. like Full Name field will only allow to enter alphabet and phone number only allow numbering. this two function is working fine with the code below.
function checkname($name)
{
if (!$name || !preg_match("/^[a-z @]+$/i",$name)){
return false;
}
return $name;
}
function checkphone($tel_hp)
{
if (!$tel_hp || !preg_match("/^[0-9-]+$/i",$tel_hp)){
return false;
}
return $tel_hp;
}
Now i would like to add in a field length validation for postcode,
Example: if the post code field enter more than 5 or less than 5 digit, the error message will show out.
But i have no ideal how to check the length, below is the code i try and actually not work. I hope to get any one have experience or ideal to do the length validation.
function checkpost($post)
{
for ($i=0; $i<strlen($post); $i++) {
if ($post.charAt(i) < 5){
return false;
}
}
return $post;
}