Skip to content

Commit c761172

Browse files
Create 193. Valid Phone Numbers.sh
1 parent 59e4c03 commit c761172

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

193. Valid Phone Numbers.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#Bash script to check for valid phone number
2+
#Valid: XXX-XXX-XXXX or (XXX) XXX-XXXX
3+
4+
grep -E '^[0-9]{3}-[0-9]{3}-[0-9]{4}$|^\([0-9]{3}\) [0-9]{3}-[0-9]{4}$' file.txt
5+
6+
:'
7+
^ start line
8+
$ end line
9+
\ escape trailing character
10+
() grouping
11+
[0-9]{3}-[0-9]{3}-[0-9]{4}$
12+
XXX-XXX-XXXX
13+
([0-9]{3}\) [0-9]{3}-[0-9]{4}
14+
(XXX) XXX-XXXX
15+
'

0 commit comments

Comments
 (0)