Return to Snippet

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

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

function is_valid_password($pwd){
// accepted password length between 5 and 20, start with character.
    if (preg_match("/^[a-zA-Z][[email protected]#^&]{5,20}$/", $pwd))
        return true;
        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

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