function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Srinu@dreamsSrinu@dreams 

How to make the input field to accept only email format of data

Example: xxxxxxxxx@xxxx.com

Best Answer chosen by Admin (Salesforce Developers) 
SamuelDeRyckeSamuelDeRycke

if your inputfield is an sObject field you can use a validation rule  with a regex expression  (REGEX( Social_Security_Number__c , "[0-9]{3}-[0-9]{2}-[0-9]{4}") ) for instance

 

if not an sObject field you can do it in apex, for instance  :

 

String InputString = 'email@email.com';
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);

// Then instantiate a new Matcher object "MyMatcher"
Matcher MyMatcher = MyPattern.matcher(InputString);

if (!MyMatcher.matches()) {
// invalid, do something
}

source: http://salesforcesource.blogspot.be/2010/01/utilizing-apex-pattern-and-matcher.html  

 

 

email validation regular expressions should be abundant to find with a search engine.