Skip to content

Instantly share code, notes, and snippets.

@orangexception
Created October 14, 2011 19:52
Show Gist options
  • Save orangexception/1288132 to your computer and use it in GitHub Desktop.
Save orangexception/1288132 to your computer and use it in GitHub Desktop.
Regular Expression to match partial email or phone number.
# Problem
Find partial valid email address or partial phone number.
# Answer
^(([\w_]+@))||((\d[\d-]*))$
It's not a perfect solution, but it'll work for the given test cases.
# Given Test Cases
## EMAIL
jimmy <-- should fail
jimmy-the-hand <-- should fail
dashel_jameson@ <-- should pass
grayson@ <-- should pass
weird_al_yankovic@ <-- should pass
al+sharpton@ <-- should fail
a798s@ <-- should pass
## PHONE
615-555-1212 <-- should pass
615 - A <-- should fail
419 <-- should pass
22 <-- should pass
2b <-- should fail
12b <-- should fail
1 <-- should pass
### Test Cases Only
jimmy
jimmy-the-hand
dashel_jameson@
grayson@
weird_al_yankovic@
al+sharpton@
a798s@
615-555-1212
615 - A
419
22
2b
12b
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment