Javascript String Character Checking -
what best way check javascript string @ least 4 characters long, contains @ least 1 lowercase letter, 1 uppercase letter , digit?
testing lowercase letters has been covered elsewhere:
function haslowercase(str) { return (/[a-z]/.test(str)); }
it's trivial modify implement hasuppercase
, hasdigits
.
once have written these functions, can check that:
if( haslowercase(passwd) && hasuppercase(passwd) && hasdigits(passwd) ) { // valid password! }
if use in many places, consider making new function:
function ispasswordvalid(str) { return haslowercase(passwd) && hasuppercase(passwd) && hasdigits(passwd); }
which can further use like:
if( ispasswordvalid("passwd") ) { // ... }
Comments
Post a Comment