Skip to content

Instantly share code, notes, and snippets.

@pgburt

pgburt/index.js Secret

Created January 8, 2016 21:40
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 pgburt/897ca670bba77d042585 to your computer and use it in GitHub Desktop.
Save pgburt/897ca670bba77d042585 to your computer and use it in GitHub Desktop.
Regex is a cruel companion.
#!/usr/bin/env node
var validate = require('data-validate');
var protocol = "(https?|ftp)\:\/\/"
var uri = "[^\s/?\.#-]+"
var pattern = new RegExp(protocols + uri)
var valid = validate.is(pattern)('http://example.com')
var invalid = validate.is(pattern)('jesse@example.com')
console.log(
"valid is: ", valid,
"\ninvalid is: ", invalid
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment