I suggest you learn more about regular expressions from somewhere. In the comments, Daniel Vandersluis has a really good point: Addresses can't be verified by merely a regex.The USPS has an entire division called CASS (Coding Accuracy Support System) dedicated to verifying address data.
In MVC razor we should use @@ symbol to perform validation.Addresses can appear in many, many formats, and even if something looks like an address it doesn't mean that it's an actual valid address (ie."123 Main Street" looks like an address, but maybe #123 was skipped or the street only has addresses up to #90).But keep in mind that one should not rely only upon Java Script validation. This should be validated on the server side as well.Here's an example of the above in action: Almost all answers to this questions suggest using Regex to validate emails addresses.It is a very simple function which uses a regular expression pattern match to test if a email is of a correct format. This takes in a parameter of the email address and then runs a pattern match against the regular expression.
If it doesn't find any matches then it will fail the validation and the function will return false, if the match returns true then the email will be of a correct format and the function will return true.
But what if I told you there were a way to determine whether or not an email is valid without resorting to regular expressions at all? The activation email is a practice that’s been in use for years, but it’s often paired with complex validations that the email is formatted correctly.
It’s surprisingly easy, and you’re probably already doing it anyway. If you’re going to send an activation email to users, why bother using a gigantic regular expression?
//reported to validate incorrectly: [email protected] as true /[A-Z0-9._% -] @[A-Z0-9-] .
Though this solution may be simple, I'm sure this is one of those useful things that people will be Googling for and deserves its own entry on the site If only Google would be the first place to look :) Just look at the duplicates of this closed every some time.
They can get ridiculously convoluted as in the case above and, according to the specification, are often too strict anyway.