Skip to content

Instantly share code, notes, and snippets.

@TzuYangLin
Last active August 29, 2015 14:07
Show Gist options
  • Save TzuYangLin/74d118797c221ed2ed49 to your computer and use it in GitHub Desktop.
Save TzuYangLin/74d118797c221ed2ed49 to your computer and use it in GitHub Desktop.
Javascript: Check text format
// Function 1, return true or false.
(/^[a-zA-Z0-9\.\_\-]*$/g.test(document.getElementById("id").value)
// Function 2, return 0 is normal.
document.getElementById("id").value.search(/[^0-9_]/)
//Check Email Format, return 0 is error.
// Rules: 1. Just 1 '@'
// 2. At least one '.' in the URL and can't 1 by 1
// 3. No space
var regExp =/^[^@^\s]+@[^\.@^\s]+(\.[^\.@^\s]+)+$/;docu
ment.getElementById("sener").vlue.match(regExp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment