Password Validataions (JAVA & TypeScript)
public static Boolean hasSpecialCharacter(String strPassword)
{
Boolean bHasSpecialCharacter = Pattern.matches("^(?=.*[\\x21-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\x7e]).{1,}", strPassword);
if(true == bHasSpecialCharacter)
{
System.out.println(strPassword + " has Special Character.");
}
else
{
System.out.println(strPassword + " has no Special Character.");
}
return bHasSpecialCharacter;
}
public static Boolean isValidPassword(String strPassword)
{
Boolean bValid = Pattern.matches("^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\\x21-\\x2f|\\x3a-\\x40|\\x5b-\\x60|\\x7b-\\x7e]).{10,16}", strPassword);
System.out.println(strPassword + ":" + bValid);
return bValid;
}
public static Boolean hasAlphabet(String strPassword)
{
Boolean bHasAlphabet = Pattern.matches("^(?=.*[a-zA-Z]).{1,}", strPassword);
if(true == bHasAlphabet)
{
System.out.println(strPassword + " has Alphabet.");
}
else
{
System.out.println(strPassword + " has no Alphabet.");
}
return bHasAlphabet;
}
public static Boolean hasDigit(String strPassword)
{
Boolean bHasDigit = Pattern.matches("^(?=.*[\\d]).{1,}", strPassword);
if(true == bHasDigit)
{
System.out.println(strPassword + " has Digits.");
}
else
{
System.out.println(strPassword + " has no Digits.");
}
return bHasDigit;
}
public static void testPassword(String strPassword)
{
System.out.println("Your password is : " + strPassword);
hasAlphabet(strPassword);
hasDigit(strPassword);
hasSpecialCharacter(strPassword);
}
function hasAlphabet(strPassword: string) {
const reg = new RegExp("^(?=.*[a-zA-Z]).{1,}$")
const bHasAlphabet = reg.test(strPassword)
if(false === bHasAlphabet) {
console.log(`${strPassword} has no alphabet.`)
} else {
console.log(`${strPassword} has alphabet.`)
}
return bHasAlphabet
}
function hasDigit(strPassword: string) {
const reg = new RegExp("^(?=.*[0-9]).{1,}$")
const bHasDigit = reg.test(strPassword)
if(false === bHasDigit) {
console.log(`${strPassword} has no digit.`)
} else {
console.log(`${strPassword} has digit.`)
}
return bHasDigit
}
function hasSpecialCharacter(strPassword: string) {
const reg = new RegExp("^(?=.*[\\x21-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\x7e]).{1,}$")
const bHasSpecialCharacter = reg.test(strPassword)
if(false === bHasSpecialCharacter){
console.log(`${strPassword} has no special character.`)
} else {
console.log(`${strPassword} has special character.`)
}
return bHasSpecialCharacter
}
function isValidPassword(strPassword: string) {
const reg = new RegExp("^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\\x21-\\x2f|\\x3a-\\x40|\\x5b-\\x60|\\x7b-\\x7e]).{10,16}$")
const bValid = reg.test(strPassword)
if(false === bValid) {
console.log(`${strPassword} is invalid.`)
} else {
console.log(`${strPassword} is valid.`)
}
return bValid
}
function testPassword(strPassword: string) {
console.log(`Your Password is : ${strPassword}`)
hasAlphabet(strPassword)
hasDigit(strPassword)
hasSpecialCharacter(strPassword)
isValidPassword(strPassword)
}