Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
129
rated 0 times [  134] [ 5]  / answers: 1 / hits: 51092  / 14 Years ago, tue, november 30, 2010, 12:00:00

i made that:



 /^(http[s]?://){0,1}(www.){0,1}[a-zA-Z0-9.-]+.[a-zA-Z]{2,5}[.]{0,1}


and checked it with a validator but on my page it is not working:



var re = /^(http[s]?://){0,1}(www.){0,1}[a-zA-Z0-9.-]+.[a-zA-Z]{2,5}[.]{0,1};
if (!re.test(url)) {
alert(url error);
return false;
}


i get this error



Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)
Timestamp: Tue, 30 Nov 2010 14:23:10 UTC


Message: Expected ')' in regular expression
Line: 781
Char: 23
Code: 0
URI: http://*************************

More From » regex

 Answers
80

You have to escape your special characters (/ and that . after www in this case) and att the missing trailing /, like this:



var re = /^(http[s]?://){0,1}(www.){0,1}[a-zA-Z0-9.-]+.[a-zA-Z]{2,5}[.]{0,1}/;
if (!re.test(url)) {
alert(url error);
return false;
}

[#94791] Saturday, November 27, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aleenamarinr

Total Points: 610
Total Questions: 109
Total Answers: 118

Location: Mayotte
Member since Mon, Sep 12, 2022
2 Years ago
;