Interviewer And Interviewee Guide

Scripting Interview Question:

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

Submitted by: Administrator
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;
}
Submitted by: Administrator

Read Online Scripting Job Interview Questions And Answers
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.