Scripting Question:
Download Questions PDF

Explain how to validate website address using JavaScript? User should not be allowed to enter special characters except hyphen(-)?

Scripting Interview Question
Scripting Interview Question

Answer:

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;
}

Download Scripting Interview Questions And Answers PDF

Previous QuestionNext Question
Do you know how to create "Double Line Hyperlink" in HTML?How to disable back button in Mozilla?