Skip to content

Instantly share code, notes, and snippets.

@kujyp
Created November 9, 2019 09:21
Show Gist options
  • Save kujyp/67b8ad602842c07fcadff56960b4dcf7 to your computer and use it in GitHub Desktop.
Save kujyp/67b8ad602842c07fcadff56960b4dcf7 to your computer and use it in GitHub Desktop.
isPhoneNumberThenEchoYes
#!/bin/bash -e
function isPhoneNumberThenEchoYes() {
if [[ "${1-}" =~ ^([0-9]{2}|[0-9]{3})(-| )?([0-9]{3}|[0-9]{4})(-| )?[0-9]{4}$ ]]; then
echo yes
else
echo no
fi
}
isPhoneNumberThenEchoYes "0"
isPhoneNumberThenEchoYes "a"
isPhoneNumberThenEchoYes "01012345678"
isPhoneNumberThenEchoYes "010-1234-5678"
isPhoneNumberThenEchoYes "010-12345678"
isPhoneNumberThenEchoYes "010 1234 5678"
isPhoneNumberThenEchoYes "010 123 5678"
isPhoneNumberThenEchoYes "02 123 5678"
isPhoneNumberThenEchoYes "02 1234 5678"
isPhoneNumberThenEchoYes "aa1234 5678"
@kujyp
Copy link
Author

kujyp commented Nov 9, 2019

결과:

[root@5dbac5e8fb4e /]# isPhoneNumberThenEchoYes "0"
no
[root@5dbac5e8fb4e /]# isPhoneNumberThenEchoYes "a"
no
[root@5dbac5e8fb4e /]#
[root@5dbac5e8fb4e /]# isPhoneNumberThenEchoYes "01012345678"
yes
[root@5dbac5e8fb4e /]# isPhoneNumberThenEchoYes "010-1234-5678"
yes
[root@5dbac5e8fb4e /]# isPhoneNumberThenEchoYes "010-12345678"
yes
[root@5dbac5e8fb4e /]# isPhoneNumberThenEchoYes "010 1234 5678"
yes
[root@5dbac5e8fb4e /]# isPhoneNumberThenEchoYes "010 123 5678"
yes
[root@5dbac5e8fb4e /]# isPhoneNumberThenEchoYes "02 123 5678"
yes
[root@5dbac5e8fb4e /]# isPhoneNumberThenEchoYes "02 1234 5678"
yes
[root@5dbac5e8fb4e /]# isPhoneNumberThenEchoYes "aa1234 5678"
no

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment