KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > utils > DataValidator


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12

13 //
14
// DataValidator
15
// MJ 08.01.2001
16
//
17
//
18

19 package org.jahia.utils;
20
21 import org.apache.regexp.RE;
22 import org.apache.regexp.RESyntaxException;
23
24
25
26 /**
27  * Utility class for data validation.
28  *
29  * @author MJ
30  */

31
32
33 public class DataValidator
34 {
35     
36     private static RE emailRE;
37     
38     static {
39         try {
40             emailRE = new RE("^[\\w\\-\\._=\\!#\\*\\+]+@((([\\w\\-]+\\.)+[a-zA-Z]{2,3})|localhost)$");
41         } catch (RESyntaxException e) {
42             String JavaDoc errorMsg = "RE exception : " + e.getMessage();
43             JahiaConsole.println( "DataValidator", errorMsg );
44         }
45     }
46
47     /**
48      * Checks whether an email address is valid.
49      *
50      * @param email The email address to check.
51      * @return Whether the email is valid.
52      */

53     public static boolean isValidEmail (String JavaDoc email)
54     {
55         return (email != null && emailRE.match(email));
56     }
57
58 }
59
Popular Tags