Skip to content

Instantly share code, notes, and snippets.

@unknownuser88
Created January 6, 2014 13:25
Show Gist options
  • Save unknownuser88/8282856 to your computer and use it in GitHub Desktop.
Save unknownuser88/8282856 to your computer and use it in GitHub Desktop.
search(regexp) Tests for a match in a string. It returns the index of the match, or -1 if not found.
//search(regexp)
var intRegex = /[0-9 -()+]+$/;
var myNumber = '999';
var isInt = myNumber.search(intRegex);
console.log(isInt);
//output: 0
var myString = '999 JS Coders';
var isInt = myString.search(intRegex);
console.log(isInt);
//output: -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment