Skip to content

Instantly share code, notes, and snippets.

@ekinertac
Forked from alioguzhan/validate.js
Created March 22, 2013 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekinertac/5225610 to your computer and use it in GitHub Desktop.
Save ekinertac/5225610 to your computer and use it in GitHub Desktop.
// Validate Phone Format
var filter = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;
// Validate Email Format
var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,6}|[0-9]{1,3})(\]?)$/;
// Validate Date Format (Short Date mm/dd/yyyy)
var filter = /^(0?[1-9]|1[012])\/(0?[1-9]|[12][0-9]|3[01])\/(?:19|20|21\d{2})/;
// Validate URL Format
var filter = /^(ftp|http|https):\/\/[A-Za-z0-9\.-]{1,}\.[A-Za-z]{2}/
// To Verify if a text has the right format
var result = filter.test(textToValidate);
// NOTE: result will be true if format is correct otherwise false.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment