Created
October 14, 2011 19:52
-
-
Save orangexception/1288132 to your computer and use it in GitHub Desktop.
Regular Expression to match partial email or phone number.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
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