/    Sign up×
Community /Pin to ProfileBookmark

Form Validation

Hello:

I could use some help. I have a form where I’m having people enter URL’s into textboxes that should not contain URL’s.

How can I write a form validation script where I can check that each textbox field does NOT have a URL in it?

For example, the phone number textbox field should only accept a valid phone number (###) ###-####. The name textbox field should only contain letters (no numbers or characters).

Can someone help me write something?

Thank you.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@CodericJun 13.2009 — Maybe something like this using "regular expressions" ?

[CODE]function checkPhone(strPhone)
{
var regPhone = /^(+d)*s*((d{3})s*)*d{3}(-{0,1}|s{0,1})d{2}(-{0,1}|s{0,1})d{2}$/;
if (strPhone.match(regPhone))
{
return true;
}
else
{
window.alert("Please enter a valid telephone number");
return false;
}
}[/CODE]


Here is a tutorial link : http://javascriptkit.com/javatutors/re.shtml
Copy linkTweet thisAlerts:
@CodericJun 13.2009 — This one would be easier to follow, sorry for the double-post but I couldn't edit the last one....

function checkPhone(strPhone) {

var regPhone = /^(ddd) ddd-dddd$/;


if (strPhone.match(regPhone))


{

return true;

}

else

{

window.alert("Please enter a valid telephone number");

return false;

}

}
[/QUOTE]
Copy linkTweet thisAlerts:
@hbradshawauthorJun 18.2009 — Thank you. I'll give it a try.
×

Success!

Help @hbradshaw spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...