Remember:
function returns 1 if the format is correct
function returns 0 if the entered format is incorrect.
Code is as follows:
<?php
function name_validate($str)
{
return preg_match("/^[A-Za-z]+$/",$str);
}
function email_validate($str)
{
return preg_match("/^[A-Za-z0-9_.+-]+@[A-Za-z0-9_.+-]+\.[a-zA-Z0-9-.]+$/",$str);
}
function username_validate($str)
{
return preg_match("/^[A-Za-z0-9_-]{6,12}+$/",$str);
}
function password_validate($str)
{
return preg_match("/^[A-Za-z0-9_@#$%\^&+=]{6,12}+$/",$str);
}
?>
To get a basic idea about regex read this.
Use these functions appropriately and if you have any doubts please ask through comments.
No comments:
Post a Comment