Reputation: 10161
I am trying to do the following in the console of IE8
new RegExp(/(^(([+]?((([0-9\u0660-\u0669]+)([\,\.\-]?[\s]?))+))+){4,255}$)|(^[]{0,255}$)/).test('1234')
and I am getting the following error "Expected ']'
in regular expression" but whenever I try this on Firefox it returns true with no errors what so ever.
I am unable to figure where in the regular expression, the problem lies. Any help would be much appreciated.
Upvotes: 0
Views: 1380
Reputation: 3446
Why not using (^$) to match the empty string?
new RegExp(/(^(([+]?((([0-9\u0660-\u0669]+)([\,\.\-]?[\s]?))+))+){4,255}$)|(^$)/).test('')
//true
new RegExp(/(^(([+]?((([0-9\u0660-\u0669]+)([\,\.\-]?[\s]?))+))+){4,255}$)|(^$)/).test('1234')
//true
new RegExp(/(^(([+]?((([0-9\u0660-\u0669]+)([\,\.\-]?[\s]?))+))+){4,255}$)|(^$)/).test('abc')
//false
That is, unless you need to match from 0 to 255 spaces along with the number part.
Upvotes: 3
Reputation: 11807
new RegExp(/(^(([+]?((([0-9\u0660-\u0669]+)([\,\.\-]?[\s]?))+))+){4,255}$)|(^[ ]{0,255}$)/).test('1234')
Put a space between [ ]
at: (^[ ]{0,255}$)/)
Upvotes: 2