Skip to main content
added 2 characters in body
Source Link
Sneh
  • 1.1k
  • 1
  • 8
  • 9

To check length use below:

if(stringToCheck.length < 4 || stringToCheck.length > 12){
 //throw error
}

To not allow small letters a-z use below:

const regex = /[a-z]/;
if(regex2.test(stringToCheck)){
 //if a-z is entered throw error
 //this will allow A-Z, 0-9, '-'.... 
 //throw error
}

To must contain at least one digit use below:

const regex = /\d/;
if(!regex2.test(stringToCheck)){
 //if no digit is entered throw error
 //throw error
}

To check length use below:

if(stringToCheck.length < 4 || stringToCheck.length > 12){
 //throw error
}

To not allow small letters a-z use below:

const regex = /[a-z]/
if(regex2.test(stringToCheck)){
 //if a-z is entered throw error
 //this will allow A-Z, 0-9, '-'.... 
 //throw error
}

To must contain at least one digit use below:

const regex = /\d/
if(!regex2.test(stringToCheck)){
 //if no digit is entered throw error
 //throw error
}

To check length use below:

if(stringToCheck.length < 4 || stringToCheck.length > 12){
 //throw error
}

To not allow small letters a-z use below:

const regex = /[a-z]/;
if(regex2.test(stringToCheck)){
 //if a-z is entered throw error
 //this will allow A-Z, 0-9, '-'.... 
 //throw error
}

To must contain at least one digit use below:

const regex = /\d/;
if(!regex2.test(stringToCheck)){
 //if no digit is entered throw error
 //throw error
}
Source Link
Sneh
  • 1.1k
  • 1
  • 8
  • 9

To check length use below:

if(stringToCheck.length < 4 || stringToCheck.length > 12){
 //throw error
}

To not allow small letters a-z use below:

const regex = /[a-z]/
if(regex2.test(stringToCheck)){
 //if a-z is entered throw error
 //this will allow A-Z, 0-9, '-'.... 
 //throw error
}

To must contain at least one digit use below:

const regex = /\d/
if(!regex2.test(stringToCheck)){
 //if no digit is entered throw error
 //throw error
}