We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Monday, November 5, 2018

Some Common Regular Expressions

File validationa

Regular expression to validate file formats for .mp3 or .MP3 or .mpeg or .MPEG or m3u or M3U


Re= /^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.mp3|.MP3|.mpeg|.MPEG|.m3u|.M3U)$/;

Regular expression to validate file formats for .doc or .docx

Re= /^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.doc|.docx|.DOC|.DOCX)$/;

Regular expression to validate file formats for .txt or .TXT

Re= /^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.txt|.TXT)$/;

Regular expression to validate file formats for .jpeg or .JPEG or .gif or .GIF or .png or .PNG

Re= /^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.jpeg|.JPEG|.gif|.GIF| .png|.PNG)$/;


 ->Regular expression to validate file formats for Name:

Re=^[a-zA-Z''-'\s]{1,40}$

Description:-Validates a name. Allows up to 40 uppercase and lowercase characters and a few special characters that are common to some names. We can modify this list.

->Regular expression to validate file formats for Social Security Number:
Re=^\d{3}-\d{2}-\d{4}$   (Ex:111-11-1111)
Description:-Validates the format, type, and length of the supplied input field. The input must consist of 3 numeric characters followed by a dash, then 2 numeric characters followed by a dash, and then 4 numeric characters.

 ->Regular expression to validate file formats for Phone Number:

Re=^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$  (Ex:-123-666-0875)


Validates a U.S. phone number. It must consist of 3 numeric characters, optionally enclosed in parentheses, followed by a set of 3 numeric characters and then a set of 4 numeric characters.



->Regular expression to validate file formats for E-mail:


^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$


Validates an e-mail address.



->Regular expression to validate file formats for URL:


^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&amp;%\$#_]*)?$


Validates a URL.



->Regular expression to validate file formats for ZIP Code:

^(\d{6}-\d{5}|\d{6}|\d{9})$|^([a-zA-Z]\d[a-zA-Z] \d[a-zA-Z]\d)$ (Ex:123456)


 Description:Validates a U.S. ZIP Code. The code must consist of 5 or 9 numeric characters.

->Regular expression to validate file formats for Password:
(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,10})$
Validates a strong password. It must be between 8 and 10 characters, contain at least one digit and one alphabetic character, and must not contain special characters.

->Regular expression to validate file formats for Non- negative integer:
^\d+$
Validates that the field contains an integer greater than zero.

->Regular expression to validate file formats for Currency (non- negative):
^\d+(\.\d\d)?$
Validates a positive currency amount. If there is a decimal point, it requires 2 numeric characters after the decimal point. For example, 3.00 is valid but 3.1 is not.

->Regular expression to validate file formats for Currency (positive or negative):
^(-)?\d+(\.\d\d)?$

Validates for a positive or negative currency amount. If there is a decimal point, it requires 2 numeric characters after the decimal point.

No comments: