Return to Snippet

Revision: 65111
at October 25, 2013 14:55 by codingforever99


Initial Code
<?php
 
function is_valid_username($username){
// accepted username length between 5 and 20
    if (preg_match('/^\w{5,20}$/', $username))
        return true;
    else
        return false;
}


function is_valid_password($pwd){
// accepted password length between 5 and 20, start with character.
    if (preg_match("/^[a-zA-Z][0-9a-zA-Z_!$@#^&]{5,20}$/", $pwd))
        return true;
    else
        return false;
}


function is_valid_date($date){
//============ date format dd-mm-yyyy
if(preg_match("/^(\d{2})-(\d{2})-(\d{4})$/", $date, $sdate))
    if(checkdate($sdate[2], $sdate[1], $sdate[3]))
        return true;
}

?>

Initial URL
http://function-code.blogspot.com/2013/10/username-password-and-date-validation.html

Initial Description
Simple PHP functions to validate username, password and date, functions check the input format and allowed characters and then return TRUE for valid data and FALSE for invalid data.

Initial Title
username, password and date validation with php

Initial Tags
php, date, validation

Initial Language
PHP