Created
March 26, 2015 16:06
-
-
Save majidmushtaq91/07163f32cb13547d9e87 to your computer and use it in GitHub Desktop.
PHP - Validate password limit and special characters.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
</head> | |
<body> | |
<?php if($_POST) { | |
function validate_input($val = "") { | |
$output = ""; | |
$validate = preg_match('/^[-a-zA-Z0-9 .]+$/', $_POST["password"]); | |
$validate2 = preg_match('/[@.?(),!-]/', $_POST["password"]); | |
if(strlen($_POST["password"]) < 8 || strlen($_POST["password"]) > 12) { | |
$output = "Please enter password between 8-12"; | |
} | |
if(!$validate && !$validate2) { | |
$output = "This Special character not allowed"; | |
} | |
return $output; | |
} | |
echo validate_input($_POST); | |
} | |
?> | |
<form action="" method="POST"> | |
<input type="password" name="password" id="password" > | |
<input type="submit" name="submit" value="submit"> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment