I have added jQuery validator add method for the presence of http check in url field.
JS
jQuery.validator.addMethod("valid_url", function(value, element) {
if(!/^(https?|ftp):\/\/i.test(val))
val = 'http://'+val; // set both the value
$(elem).val(val); // also update the form element
}
My Console throws
"unterminated regular expression literal" error in the following line.
if(!/^(https?|ftp):\/\/i.test(val))
What my mistake is?
I have added jQuery validator add method for the presence of http check in url field.
JS
jQuery.validator.addMethod("valid_url", function(value, element) {
if(!/^(https?|ftp):\/\/i.test(val))
val = 'http://'+val; // set both the value
$(elem).val(val); // also update the form element
}
My Console throws
"unterminated regular expression literal" error in the following line.
if(!/^(https?|ftp):\/\/i.test(val))
What my mistake is?
Share Improve this question asked Nov 9, 2013 at 6:24 SamSam 5,26012 gold badges48 silver badges98 bronze badges2 Answers
Reset to default 8Regular expression literals should be surrounded by the delimiters(/
). There's no terminating delimiter:
/^(https?|ftp):\/\//i
// ^
For example:
>> /^(https?|ftp):\/\//i.test('http://stackoverflow./')
true
>> /^(https?|ftp):\/\//i.test('telnet://stackoverflow./')
false
You can also get this error if you're simply attempting to concatenate a variable that utilizes a regular expression and forget a quotation mark somewhere.