In a combined regex it looks like working and it is failing when am using it in pattern. please help.
^(?=.*\\p{Nd})(?=.*\\p{L})(?!.*(.{2,})\\1).{5,12}$
this seems to be working but when I split it's failing.
^(?=.*\\p{Nd})(?=.*\\p{L})
Also I am looking for UNICODE validation to ignore any special character and just accept mixture of letters/Alpha & digits (atleast one alpha and one digit)
public void setValidations(){
validation1 = "^(?=.*\\p{Nd})(?=.*\\p{L})"; //this is failing
validation2 = "^.{5,12}$";
validation3 = "(\\S+?)\\1";
p1 = Pattern.compile(validation1);
p3 = Pattern.compile(validation3);
}
public boolean validateString(String str){
matcher1 = p1.matcher(str);
matcher3 = p3.matcher(str);
if(matcher1.find()){ //Expecting string passed "invalid" to fail (no numeric in it)
System.out.println(str + " String must have letters & number at least one");
return false;
}
if (!str.matches(validation2)){
System.out.println(str + " String must be between 5 and 12 chars in length");
return false;
}
if (matcher3.find()){
System.out.println(str + " got repeated: " + matcher3.group(1) + " String must not contain any immediate repeated sequence of characters");
return false;
}
return true;
}
public static void main(String[] args) {
StringValidation sv = new StringValidation();
String s2[] = {"1newAb", "A1DOALDO", "1234567AaAaAaAa", "123456ab3434", "$1214134abA", "invalid"};
boolean b3;
for(int i=0; i<s2.length; i++){
b3 = s2[i].matches("^(?=.*\\p{Nd})(?=.*\\p{L})(?!.*(.{2,})\\1).{5,12}$");
System.out.println(s2[i] + " "+ b3); // string "invalid" returning false (expected)
}
for (String str : s2) {
if(sv.validateString(str))
System.out.println(str + "String is Valid");
}
}
Also I want "$1214134abA" this string to fail since it has $