Validation in Java


Validations:


1. If word contains consecutive characters

String userWord = "Pankaj";
Pattern pattern = Pattern.compile("(\\w)\\1{2,}");
Matcher matcher = pattern.matcher(userWord);
if (matcher.find()) {
System.out.println("Found value is: " + matcher.group(0));
return true;
} else {
System.out.println("NO MATCH");
return false;
}


2. If word contains more instance of characters

String userWord = "Pankaj";
Pattern pattern = Pattern.compile("(\\w)(\\w*\\1){4}");
Matcher matcher = pattern.matcher(userWord);
if (matcher.find()) {
System.out.println("Found value is: " + matcher.group(0));
return true;
} else {
System.out.println("NO MATCH");
return false;
}


3. If word contains any name

String firstName = "Pankaj";
String emailAddress = "pankaj.lilhare@gmail.com";
// Here I want to check first name is exist on given emailAddress.

return (firstName.toUpperCase().matches("(.*)"+emailAddress.toUpperCase()+"(.*)")) ? true :false;


4. To check name should not contains Consecutive special characters like - _ . and space

Pattern pattern = Pattern.compile("[-_. ][-_. ]");


5. To check name should not start with special characters

Pattern pattern = Pattern.compile("^[?<>~!@#$%^&()`,.{}|;:*'\\[\\]\\-_=+\"\\/\\\\ ]");


6. To check name should not ends with special characters

Pattern pattern = Pattern.compile("[?<>~!@#$%^&()`,.{}|;:*'\\[\\]\\-_=+\"\\/\\\\ ]$");



For passsword validation (?!.*([A-Za-z0-9@!#$%^&*(){}?;:,./<>])\1{2})((?=.*\d)|(?=.*[@!#$%^&*(){}?;:,./<> ]))(?=.*[a-z])(?=.*[A-Z]).{8,}

Comments

Popular posts from this blog

XML Parsing in IBM BPM

Type conversion in IBM BPM

Parse the JSON in IBM BPM