A few handy validation Regular Expressions

I’ve jumped into RegEx without much experience and thought adding a starter set of validations might help others get some basic functionality into their forms more quickly (and save the time I spent Googling and trial and error).

Mandatory Valid Email

By design this rule ensures domain formatting has no spaces, commas, double full stops or end with a full stop.

Email is a tricky one to validate because almost almost anything before the “@” can be valid if it’s within quotes. For that reason, this simple rule states:

  1. There must be something before the @
  2. There must be an @
  3. After the @ must follow characters that do not include a comma, full stop or a space
  4. Next must follow at least one group that starts with a full stop before a string of characters excluding a comma, full stop or a space

RegEx = ^.+@([^,\.\ ])+(\.([^,\.\ ])+)+$

Phone number - Min 10 digits (not mandatory)

Domestic phone numbers in Australia (standard landline or mobile) which inlclude an area code, are a minimum of 10 digits. So making sure a phone number has a minimum of 10 is a sufficient test. Even if users add brackets, spaces, + or dashes it will pass. So people adding international codes or extension numbers won’t be penalised. Of course, promotional business numbers may get blocked, such as 130 000, or 911.

RegEx = ^(\D*(?:\d\D*){10,})?$

Valid Australian Landline or Mobile Phone Number

If you want to get very strict in Australia, you can mandate a strict landline or mobile number format. I doubt it’s required though, unless you’re sure your audience is domestic only, in which case it might slow down a few spam bots.

RegEx = ^(\({0,1}((0|\+61)(2|4|3|7|8)){0,1}\){0,1}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{1}(\ |-){0,1}[0-9]{3})?$


This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/84963-a-few-handy-validation-regular-expressions