/    Sign up×
Community /Pin to ProfileBookmark

Numbers only when validating number

Hi,

I’m trying to validate a phone number, where only numbers can be entered in, but it doesn’t seem to work

Here’s my code:

[CODE]<html>
<head>
<title>Form Validation</title>
<link href=”xxx.css” rel=”stylesheet” type=”text/css”/>
<script language=”JavaScript” type=”text/javascript”>

function validatePhone() {
var error = “”;
var stripped = value.replace(/[().- ]/g, ”);

if (isNaN(parseInt(stripped))) {
error = “The phone number contains illegal characters.n”;
}
return error;
}

</script>
</head>

<body>
<p>Enter your details below:</p>

<form>
Phone Number: <input type=”text” size=”25″ name=”PhoneNumber”><br>
<input type=”submit” name=”Submit” value=”validatePhone();”>
</form>
</body>
</html>[/CODE]

Anyone know what’s wrong with it?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledMay 10.2009 — you aren't even calling the function. you need to use event, probably onsubmit. second, your function seems to use an undefined variable, in this case [b]value[/b]. you need to either pass an argument that contain the value of phone field or make a reference inside the function to the phone field so you can read it's value.
×

Success!

Help @YoungGun 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.18,
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,
)...