You need to sign in to do that
Don't have an account?

code for Email validation in apex class
Hi,
How to write a code for Email validation in apex class ....
this is my page
============
<apex:page controller="JstestController">
<apex:form id="myform">
<apex:pagemessages />
<apex:pageBlock id="myblock">
Email Address: <apex:inputText value="{!email}" id="email"/><br/><br/>
<apex:commandButton value="Click me!" action="{!checkEmail}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
class
.....................
public class JstestController
{
public String email { get; set; }
public PageReference checkEmail()
{
}
}
how to wrete email validation for input text field ....
help me.......
and yet another ...
All Answers
Hi Palli,
Try following Class :
public class JstestController
{
public String email { get; set; }
public PageReference checkEmail(){
system.debug('#####email:'+email);
String emailPattern = email;
String emailRegex = '([a-zA-Z0-9_\\-\\.]+)@((\\[a-z]{1,3}\\.[a-z]{1,3}\\.[a-z]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})';
Pattern MyPattern = Pattern.compile(emailRegex);
Matcher MyMatcher = MyPattern.matcher(email);
system.debug('#####validEmail :'+ MyMatcher.matches() );
return null;
}
}
Salesforce has standard pattern matching class. I hope above mention code will help you.
Thanks
Rishi kalia
if(Pattern.matches('[a-zA-Z0-9._-]+@[a-zA-Z]+.[a-zA-Z]{2,4}', email))
{
success
}
else
{
error
}
Regards,
Magulan D
Salesforce.com certified Force.com Developer.
SFDC Blog
If this post is your solution, kindly mark this as the solution.
Hi,
Why don't you use the built-in email field type?
Regards,
Hengky
and yet another ...
Hi All,
MAGU's marked solution does not work 100% . It does not cater for john@doe (NO .com). Crop1645 is a more complete solution. Would you please update solution to correct solution.
Regards, Ben