File tree Expand file tree Collapse file tree 4 files changed +12
-8
lines changed Expand file tree Collapse file tree 4 files changed +12
-8
lines changed Original file line number Diff line number Diff line change 1
1
# Phone Regex
2
2
3
- [ ![ Build Status] ( https://travis-ci.org/johnotander /phone-regex.svg?branch=master )] ( https://travis-ci.org/johnotander /phone-regex )
3
+ [ ![ Build Status] ( https://travis-ci.org/regexps /phone-regex.svg?branch=master )] ( https://travis-ci.org/regexps /phone-regex )
4
4
5
5
A regular expression for matching phone numbers.
6
6
@@ -29,10 +29,6 @@ phone().test('apple') // => false
29
29
30
30
* Regex from < http://stackoverflow.com/a/16702965/1378668 > .
31
31
32
- ## TODO
33
-
34
- - [ ] Don't let the regex match strings with whitespace, ` " 1234567890 " ` , with the exact option.
35
-
36
32
## License
37
33
38
34
MIT
Original file line number Diff line number Diff line change 2
2
3
3
module . exports = function ( options ) {
4
4
options = options || { } ;
5
- var regexBase = '\\s* (?:\\+?(\\d{1,3}))?[-. (]*(\\d{3})[-. )]*(\\d{3})[-. ]*(\\d{4})(?: *x(\\d+))?\\s* ' ;
5
+ var regexBase = '(?:\\+?(\\d{1,3}))?[-. (]*(\\d{3})[-. )]*(\\d{3})[-. ]*(\\d{4})(?: *x(\\d+))?' ;
6
6
7
7
return options . exact ? new RegExp ( '^' + regexBase + '$' ) :
8
- new RegExp ( regexBase , 'g' ) ;
8
+ new RegExp ( '\\s*' + regexBase + '\\s*' , 'g' ) ;
9
9
}
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " phone-regex" ,
3
- "version" : " 1 .0.0" ,
3
+ "version" : " 2 .0.0" ,
4
4
"description" : " Regular expression for phone numbers." ,
5
5
"main" : " index.js" ,
6
6
"directories" : {
Original file line number Diff line number Diff line change @@ -32,6 +32,14 @@ describe('phone-regex', function() {
32
32
it ( 'should not find a phone number if it is not exact' , function ( ) {
33
33
assert . equal ( phone ( { exact : true } ) . test ( 'apples 1 123 456 7890' ) , false ) ;
34
34
} ) ;
35
+
36
+ it ( 'should not find a phone number if there is leading whitespace' , function ( ) {
37
+ assert . equal ( phone ( { exact : true } ) . test ( ' 1 123 456 7890' ) , false ) ;
38
+ } ) ;
39
+
40
+ it ( 'should not find a phone number if there is trailing whitespace' , function ( ) {
41
+ assert . equal ( phone ( { exact : true } ) . test ( '1 123 456 7890 ' ) , false ) ;
42
+ } ) ;
35
43
} ) ;
36
44
37
45
describe ( 'g' , function ( ) {
You can’t perform that action at this time.
0 commit comments