Created
September 21, 2010 04:18
-
-
Save bikashp/589180 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
when "email" | |
regex = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i | |
when "url" | |
regex = /^(http:\/\/|https:\/\/)?(www.)?[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3})([.]?[a-zA-Z]{2})?(\/\S*)?$/i | |
when "number" | |
regex = /^\d{1,3}(\,?\d{3})*$/ | |
when "time" | |
regex = /^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?$/ | |
when "date" | |
regex = /^(\d{1,2})[\/|-|\.|\s](\d{1,2})[\/|-|\.|\s](\d{2,4})$/ | |
# Here we are just validating date format. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
when "url"
regex = /^(http|https)://[a-z0-9]+([-.]{1}[a-z0-9]+).[a-z]{2,5}(([0-9]{1,5})?/.)?$/ix
when "currency" => for USD
regex = /^$?(?:\d+|\d{1,3}(?:,\d{3})*)(?:.\d{1,2}){0,1}$/
when "number"
regex = /^\d{1,3}(,?\d{3})*$/
when "email"
regex = /\A([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})\Z/i
when "date"
regex = /^(1[0-2]|0?[1-9])/(3[01]|[12][0-9]|0?[1-9])/(?:[0-9]{2})?[0-9]{2}$/
when "time"
regex = /^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?$/
when "datetme"
regex = /^(1[0-2]|0?[1-9])/(3[01]|[12][0-9]|0?[1-9])/(?:[0-9]{2})?[0-9]{2}|(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?$/