Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Javascript validate password

let pattern = new RegExp("^(?=(.*[a-zA-Z]){1,})(?=(.*[0-9]){2,}).{8,}$"); //Regex: At least 8 characters with at least 2 numericals
    let inputToListen = document.getElementById('pass-one'); // Get Input where psw is write
    let valide = document.getElementsByClassName('indicator')[0]; //little indicator of validity of psw

    inputToListen.addEventListener('input', function () { // Add event listener on input
        if(pattern.test(inputToListen.value)){
            valide.innerHTML = 'ok';
        }else{
            valide.innerHTML = 'not ok'
        }
    });
Comment

validate password javascript

// Commonly used regular expression

// Check 2-9 characters, false if not matched, true if matched
const validateName = (name) => {
   const reg = /^[u4e00-u9fa5]{2,9}$/;
   return reg.test(name);
};
// Verify phone number
const validatePhoneNum = (mobile) => {
   const reg = /^1[3,4,5,6,7,8,9]d{9}$/;
   return reg.test(mobile);
};
// Check passwords consisting of 6 to 18 uppercase and lowercase alphanumeric underscores
const validatePassword = (password) => {
   const reg = /^[a-zA-Z0-9_]{6,18}$/;
   return reg.test(password);
};
Comment

password validation in javascript

/^            : Start
(?=.{8,})        : Length
(?=.*[a-zA-Z])   : Letters
(?=.*d)         : Digits
(?=.*[!#$%&?*^@"]) : Special characters
 $/              : End

 (/^
   (?=.*d)          //should contain at least one digit
  (?=.*[a-z])         //should contain at least one lower case
  (?=.*[A-Z])         //should contain at least one upper case
  [a-zA-Z0-9]{8,}  //should contain at least 8 from the mentioned characters
 $/)

Example:-   /^(?=.*d)(?=.*[a-zA-Z])[a-zA-Z0-9]{7,}$/
Comment

password validation in javascript

// Commonly used regular expression

// Check 2-9 characters, false if not matched, true if matched
const validateName = (name) => {
   const reg = /^[u4e00-u9fa5]{2,9}$/;
   return reg.test(name);
};
// Verify phone number
const validatePhoneNum = (mobile) => {
   const reg = /^1[3,4,5,6,7,8,9]d{9}$/;
   return reg.test(mobile);
};
// Check passwords consisting of 0 to 8
//uppercase and lowercase 
//alphanumeric underscores
const validatePassword = (password) => {
   const reg = /^[a-zA-Z0-9_]{0,9}$/;
   return reg.test(password);
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript last element 
Javascript :: nodejs convert string to date 
Javascript :: npm google map react 
Javascript :: open json javascript 
Javascript :: dart to json 
Javascript :: prevent page scrolling when a modal is open 
Javascript :: remove backslash from json 
Javascript :: socket io server 
Javascript :: react 18.2 
Javascript :: knexjs char 
Javascript :: run function periodically with setInterval 
Javascript :: EFSavechanges 
Javascript :: The DOM Parent-Child Relationship 
Javascript :: javascript undefined used with number, boolean or null 
Javascript :: JavaScript Changing Prototype 
Javascript :: javascript Tagged Templates 
Javascript :: js tilda 
Javascript :: JavaScript Object Prototypes 
Javascript :: set up express server and scraper 
Javascript :: cast uint to address in solidity 
Javascript :: How to get prime numbers using for loop in Js 
Javascript :: reactjs libphonenumber 
Javascript :: phaser create animation from canvas texture 
Javascript :: complex expression in programming 
Javascript :: after end time run function 
Javascript :: efectos javascript 
Javascript :: how to choose a weighted random array element in javascript 
Javascript :: what are array methods in javascript 
Javascript :: javascript add to a dictionary 
Javascript :: string charat 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =