Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js password validation regex

/^            : 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

how can i validate a password without regex in js

function validate() {
  var p = document.getElementById('pass').value
  var errors = []

  //if (p.length < 8) {
  //  errors.push("Your password must be at least 8 characters")
  //}
  if (p.search(/[a-z]/) < 0) {
    errors.push("Your password must contain at least one lowercase letter.")
  }
  if (p.search(/[A-Z]/) < 0) {
    errors.push("Your password must contain at least one uppercase letter.")
  }
  if (p.search(/[0-9]/) < 0) {
    errors.push("Your password must contain at least one digit.")
  }
  if(p.search(/[!@#$\%^&*()\_+.,;:-]/) < 0) {
    errors.push("Your password must contain at least one special character.")
  }
    
  if (errors.length > 0) {
    document.getElementById("errors").innerHTML = errors.join("<br>")
    return false;
  }
  return true;
}
Comment

js password validation regex

const regexPass = /(?=.*[!#$%&?^*@~() "])(?=.{8,})/; 
//eight char or longer and must have a special character
Comment

js regex for password

for REACT INPUT TAG

var errorMessage:
"Password should be 8-20 characters and include at least 1 letter, 1 number and 1 special character!",
<input name= "password",
type= "password",
placeholder= "Password",
pattern="^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{8,20}$",
required/>
Comment

PREVIOUS NEXT
Code Example
Javascript :: check if input has value javascript 
Javascript :: js id generator 
Javascript :: jquery window offset top 
Javascript :: js check if variable is string 
Javascript :: convert file to blob in angular 
Javascript :: firebase firestore delete field 
Javascript :: how to use typeof in javascript 
Javascript :: js camalcase 
Javascript :: generate guard angular 
Javascript :: javascript getminutes 2 digits 
Javascript :: js document.addEventListner 
Javascript :: remove duplicate object from array javascript 
Javascript :: check if string contains character javascript 
Javascript :: regular expression special characters 
Javascript :: remove node_modules folder mac 
Javascript :: populate dropdown using jquery from database 
Javascript :: parse csv javascript 
Javascript :: react-phone-number-input retur message in react hook form 
Javascript :: js find array return true false 
Javascript :: javascript pluck 
Javascript :: mean vs mern stack 
Javascript :: javascript object remove empty properties 
Javascript :: nodejs catch uncaught exception 
Javascript :: can we add jquery in chrome extension js code 
Javascript :: ckeditor check if empty 
Javascript :: api testing 
Javascript :: javascript find all matches in array 
Javascript :: html form post json example 
Javascript :: iiee i 
Javascript :: code challenges javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =