Wednesday, December 7, 2016

Java script regex for different value formats


Regex- ^(\d+|\d+-\d+)((,?\d+)*)$ 

Allowed number formats
9
1-18,6,3,6767,343
34,34,565,6767,122323


Decimal Number Regex : ^\d*[0-9](\.\d*[0-9])?$     
Allowed Format : 119.170 

Date Format Regex (m/d/y): ^([\d]|1[0,1,2])/([0-9]|[0,1,2][0-9]|3[0,1])/\d{4}$ 
Allowed Format : m/d/y

File Names Regex : ^[a-zA-Z0-9-_\.]+\.(pdf|txt|doc|csv)$
Allowed file name format :  
hi-file.pdf
hello1-file.txt
hello3-file.doc
hello44-file.csv

E-mail Address validation regex: ^([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]+)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(.){1}[a-zA-Z]{2,4})+$
Allowed format : javafarms@india.com

HTML Color Codes regex : ^#?([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?$
Allowed Format : #8877ff

Image Filenames Regex : ^[a-zA-Z0-9-_\.]+\.(jpg|gif|png)$
Allowed format : hi-image_file.jpg


IP Address Regex : ^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$
Allowed Format : 10.121.21.111

Multimedia Filenames Regex : ^[a-zA-Z0-9-_\.]+\.(swf|mov|wma|mpg|mp3|wav)$
Allowed Format : hi-multimedia.swf

MySQL Date Format Regex : ^\d{4}-(0[0-9]|1[0,1,2])-([0,1,2][0-9]|3[0,1])$
Allowed Format : 2016-12-07

Time Format (HH:MM) Regex : ^([0-1][0-9]|[2][0-3])(:([0-5][0-9])){1,2}$
Allowed Format : 11:29


URL regex : ^(http[s]?://|ftp://)?(www\.)?[a-zA-Z0-9-\.]+\.(com|org|net|mil|edu|ca|co.uk|com.au|gov)$
https://www.myjavafarms.com



No comments:

Post a Comment

Scrum and Scrum master

Scrum  Scrum is a framework which helps a team to work together.  It is like a rugby team (the scrum name comes from rugby game). Scrum enco...