Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func IsMail(val string) bool {

func IsPhone(val string) bool {
if strings.HasPrefix(val, "+") {
return IsMatch(val[1:], `\d{13}`)
return IsMatch(val[1:], `^\d{13}$`)
} else {
return IsMatch(val, `\d{11}`)
return IsMatch(val, `^\d{11}$`)
}
}

Expand Down
8 changes: 8 additions & 0 deletions regexp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ func TestIsPhone3(t *testing.T) {
t.Errorf("TestIsPhone3:\n Expect => %v\n Got => %v\n", expect, got)
}
}

func TestIsPhone4(t *testing.T) {
got := IsPhone("186121855232342342")
expect := false
if got != expect {
t.Errorf("TestIsPhone4:\n Expect => %v\n Got => %v\n", expect, got)
}
}