Search In This Blog

Showing posts with label Regex. Show all posts
Showing posts with label Regex. Show all posts

2016-09-27

[Regex]Check English / Spanish / Franch / Arabic characters

Keep these here as a memo.


English characters:
Public Boolean checkEnglish(String value){
    return Pattern.matches('[^a-zA-Z0-9 ]+', value);
}

Spanish characters:
Public Boolean checkSpanish(String value){
    return Pattern.matches('^[0-9a-zñáéíóúü]+', value);
}

France characters:
Public Boolean checkFrance(String value){
    return Pattern.matches('[^a-zA-Z0-9 àâäèéêëîïôœùûüÿçÀÂÄÈÉÊËÎÏÔŒÙÛÜŸÇ]', value);
}

2016-09-17

How to validate email address with Regex expression in Visualforce page by Apex

When user input email address in Visualforce page, normally need to input the email address again as a confirm email address to make cross check.

If you create a field to save confirm email address. For example, this email address will be saved to Field(Email) in object(Contact), and use inputField tag will be convenient.
<apex:inputField value="{!Contact.Email}"/>
When you try to save, Salesforce will make the format check for you.

But if confirm email address is not a field in object, you may need to check format of confirm email address by Apex. Use Pattern.matches() will be a choice.
Regex foremail format check:
'^([0-9a-zA-Z+_.-]*[0-9a-zA-Z]+[@][0-9a-zA-Z+_.-]+\\.[0-9a-zA-Z+_.-]*)$'
*example email: huang.hai@randsfdc.blogspot.jp

Return the result of format check:
return Pattern.matches('^([0-9a-zA-Z+_.-]*[0-9a-zA-Z]+[@][0-9a-zA-Z+_.-]+\\.[0-9a-zA-Z+_.-]*)$', val); 
*val is the value of email address

To check are these two email address same, you can use String.equals(). Like: emailOne.equals(emailTwo).

String.equals(): Upper char and lower char will be treated as different char.