Skip to content

Instantly share code, notes, and snippets.

@prashant1k99
Created November 29, 2019 07:20
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 prashant1k99/a342f7bf4364fd84af58e2242ddbb6a1 to your computer and use it in GitHub Desktop.
Save prashant1k99/a342f7bf4364fd84af58e2242ddbb6a1 to your computer and use it in GitHub Desktop.
Using RegExp in JS
//RegExp for URL validation - ^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$
let exp = ^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$;
function testInfo(phoneInput) {
var OK = exp.exec(phoneInput.value);
if (!OK)
window.alert(phoneInput.value + ' isn\'t a phone number with area code!');
else
window.alert('Thanks, your phone number is ' + OK[0]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment