Wednesday, March 19, 2008

Bmi Models Have To Have

call Email validation with Regular Expressions in Java Design Patterns

As a programmer, frequently leads to the problem, which entered email addresses are entered correctly. The problems which arise from it are well known. But how do I avoid such errors as a developer?

In Java and most other programming languages, a simple test with Regular Expressions are implemented. Thus, although not yet examined whether the domain or address exist, but you can rule out that the syntax of the address is incorrect. In this way, one can quickly notice any typo of the user and to point him out.

In Java could be a test like this:

public boolean validateEmail (String email) {
/ / regex pattern which the syntax of the email is verified created (".+@.+
Pattern p = Pattern.compile \\ \\. [az] + ") ;
/ / string passed is the pattern matched
p.matcher Matcher m = ( e-mail);
/ / If a valid address, it returns true. Otherwise, false
if (m.matches ()) return true;
else return false;
}

use this method to have to embed the following import in its class.

java.util.regex.Matcher import, import java.util.regex.Pattern
;

More for Regular Expressions in Java here to find .

0 comments:

Post a Comment