Last active
August 29, 2015 13:57
-
-
Save musicm122/9635212 to your computer and use it in GitHub Desktop.
Javascript Validation regex
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
var hasLowercase = function (val) { | |
var patt = new RegExp(/([a-z]+)/g);//checks for 1 or more a-z characters. | |
return patt.test(val); | |
}; | |
var hasUppercase = function (val) { | |
var patt = new RegExp(/([A-Z]+)/g);//checks for 1 or more A-Z characters. | |
return patt.test(val); | |
}; | |
var hasDigit = function (val) { | |
var patt = new RegExp(/([d]+)/g);//checks for 1 or more digit character. | |
return patt.test(val); | |
}; | |
var hasSpecialChar = function (val) { | |
//checks for 1 or more special character. this includes the following ~`!@#$%^&*()_-+={}[]|\<>,./?;':" | |
var patt = new RegExp(/([\~\`\!\@\#\$\%\^\&\*\(\)\_\+\-\=\|\}\{\\\]\[\'\;\"\:\/\.\,\?\>;\<;])+/g); | |
return patt.test(val); | |
}; | |
//using the previous set of functions this one checks for 1 uppercase, 1 lowercase, 1 digit and 1 special character | |
var IsValidExpression = function (testVal) { | |
var retval = hasLowercase(testVal) && hasUppercase(testVal) && hasDigit(testVal) && hasSpecialChar(testVal); | |
return retval; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment