Javascript for Website validation

How to validate website address using javascript? User should not be allowed to enter special characters except hyphen(-).

Questions by anandnagpal17

Showing Answers 1 - 3 of 3 Answers

anjumanohar

  • Jul 17th, 2009
 

function ValidateWebAddress(field,alerttext)
{
with(field)
{

var companyUrl =value;

var RegExp = /^(([w]+:)?//)?(([dw]|%[a-fA-fd]{2,2})+(:([dw]|%[a-fA-fd]{2,2})+)?@)?([dw][-dw]{0,253}[dw].)+[w]{2,4}(:[d]+)?(/([-+_~.dw]|%[a-fA-fd]{2,2})*)*(?(&?([-+_~.dw]|%[a-fA-fd]{2,2})=?)*)?(#([-+_~.dw]|%[a-fA-fd]{2,2})*)?$/;

i f(RegExp.test(companyUrl)) {
return true;
}
else
{
alert(alerttext);
return false;
}
}
}

Call this fuction in an if else structure
Pass the field name and an alert string

if(validate_r(website,"Need to specify your site")==false)
{
return false;
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions