Created
February 13, 2017 09:40
-
-
Save beckettkev/498f43d461a0308f66898d936b595a75 to your computer and use it in GitHub Desktop.
Validation Regular Expressions for JavaScript
This file contains hidden or 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
//Between 1 - 255 characters... | |
/^.{1,255}$/ | |
//Letters only with spaces (no numbers or special characters)... | |
/^[a-zA-Z\s]*$/ | |
//Number required... | |
/^\d+$/ | |
//Number to two decimal places... | |
/\d\.\d{2,2}?$/ | |
//Number with dashes allowed... | |
/^(\d+-?)+\d+$/ | |
//Currency with optional £ prefix... | |
/^\£?(([1-9][0-9]{0,2}(,[0-9]{3})*)|[0-9]+)?\.[0-9]{1,2}$/ | |
//Percentage with no decimal places (with opitional percentage sign)... | |
/^([0-9]|[1-9][0-9]|100)(%?)?$/ | |
//Percentage with one decimal place (with opitional percentage sign)... | |
/^(\d{0,2}(\.\d)|100(\.0))(%?)?$/ | |
//Percentage with two decimal places (with opitional percentage sign)... | |
/^(\d{0,2}(\.\d{2,2})|100(\.00))(%?)?$/ | |
//Date in english format | |
/^(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]{2}$/ | |
//Hyperlink | |
/[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/ | |
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ | |
//File extension validation... | |
/\.pdf|\.doc|\.docx|\.rtf$/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment