Code for validating email in java
Your user interface should take care of the formatting problem by having a clear documentation on the format and/or split the phone into parts (area, exchange, number) and/or have an entry mask.
The following expression is pretty lenient on the format and should accept 999-999-9999, 9999999999, (999) 999-9999.
Make sure to be in global mode (g flag), case insensitive and to have the dot all option on.
This regular expression will match all HTML tags and their attributes.
You could try to match for an extension, but there's no requirement for a file to have an extension.
There are probably dozens of way to format a phone number.
Working with Functional style validation may seem daunting at first, but is an extremely flexible, clean and powerful pattern.Generic Date("2011-02-29", "yyyy-MM-dd", false) // invalid date - 29th Feb 2011 import org.apache.commons.validator.Date Validator Date Validator date Validator=Date Instance() assert date Valid("11-02-28", "yy-MM-dd", true) assert !Generic Url(" //invalid URL assert Generic Credit Card("4111111111111111") // valid visa card number assert !Generic Credit Card("4111111111111112") // invalid visa card number assert Generic Date("2011-12-30", "yyyy-MM-dd", true) // valid date(last argument for checking strict) assert Generic Date("2011-02-28", "yyyy-MM-dd", true) // valid date - 28th Feb assert !