Home > Java, Java Misc > Couple of useful regular expressions

Couple of useful regular expressions

Here are a couple of useful regular expressions I came up with over some coffee in Java language. Haven’t tested them thoroughly 😀

// the regular expression for valid time
public static final String REGEX_TIME = “(^([0-9]|[0-1][0-9]|[2][0-3]):([0-5][0-9])(\\s{0,1})(AM|PM|am|pm|aM|Am|pM|Pm{2,2})$)|(^([0-9]|[1][0-9]|[2][0-3])(\\s{0,1})(AM|PM|am|pm|aM|Am|pM|Pm{2,2})$)”;

// the regular expression for valid phone
public static final String REGEX_PHONE = “^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$”;

// the regular expression for valid eamil
public static final String REGEX_EMAIL = “.+@.+\\.[a-z]+”;

Will add more later after some errands.

Advertisements
Categories: Java, Java Misc

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: