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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -