Question
1
Replies
2177
Views
Pedavegi
Posted: July 17, 2017
Last activity: July 17, 2017
Closed
Email ID valdation
Hi ,
Could some one help me custom validation for the Email Address (XXXX.X.XXX@example.com)
Eg: ABC.XYZ@example.com (@example.com should be constant)
only the above format the email id should be accepted.
Thanks,
Prathima
***Moderator Edit: Vidyaranjan | Updated Categories***
Hi Prathima,
You can write Edit validate rule. There you can validate the domain name should be “@example.com” and add this edit validate rule that property.
Please find the below code:
if (theValue == null || theValue.trim().equals("")) return false;
String mail="^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)+(\\.[A-Za-z]{2,})$";
java.util.regex.Pattern pattern=java.util.regex.Pattern.compile(mail);
java.util.regex.Matcher matcher = pattern.matcher(theValue);
String add = theValue;
int domain=theValue.indexOf('@');
String x=theValue.substring(domain +1,theValue.length());
if(!matcher.matches() || !x.contains("example.com")){
theProperty.addMessage("Entered email domain name should be example.com ");
return false;}
else
return true;
Let us know if this helps.
Thanks
Hemalatha