VARIOUS VALIDATION REGULAR EXPRESSIONS IN JAVA
import
java.util.regex.Matcher;
import
java.util.regex.Pattern;
public class Validation
{
Pattern p;
Matcher m;
public boolean
NumberValid(String val)
{
p=Pattern.compile("[0-9]"); //NUMBER VALIDATION
m=p.matcher(val);
return m.find();
}
public boolean
StringValid(String val)
{
p=Pattern.compile("[y||m]{1}"); //STRING VALIDATION
m=p.matcher(val);
return m.find();
}
public boolean
AlphabetsOnly(String val)
{
p=Pattern.compile("[a-zA-Z]"); //ALPHABETS VALIDATION
m=p.matcher(val);
return m.find();
}
public boolean
Mobile10num(String val)
{
p=Pattern.compile("\\d{10}"); //10 DIGIT MOBILE NUMBER VALIDATION
m=p.matcher(val);
return m.find();
}
public boolean
Email(String val)
{
String
EMAIL_REGEX = "^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$";
//EMAIL ID VALIDATION
p=Pattern.compile(EMAIL_REGEX);
m=p.matcher(val);
return m.find();
}
}
No comments:
Post a Comment