/    Sign up×
Community /Pin to ProfileBookmark

Only allow certain characters in a text box

How do you only allow certain characters to be typed into a text box, for example on a form, if i ask for a phone number, to only allow numbers to be typed in,
Mark

to post a comment
HTML

6 Comments(s)

Copy linkTweet thisAlerts:
@ray326May 13.2006 — You use an onkey* handler if you want to do it interactively or you do it more robustly on the server.
Copy linkTweet thisAlerts:
@cootheadMay 13.2006 — Hi there mark200,

here is an example...
[color=navy]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">
<!--
window.onload=function() {
document.getElementById('tel').onkeyup=function() {
if(isNaN(this.value)) {
this.value=this.value.replace(this.value.charAt(this.value.length-1),'');
}
}
}
//-->
</script>

</head>
<body>

<form action="#">
<div>
<input id="tel" type="text" />
</div>
</form>

</body>
</html>
[/color]

[i]coothead[/i]
Copy linkTweet thisAlerts:
@pcthugMay 13.2006 — The only problem is; if the user has JS disabled they can give disallowed characters as they will not be effected by the restrictions.

The only effective way to detect disallowed characters is by parsing them server-side, but by doing this there is no need for client-side restrictions.
Copy linkTweet thisAlerts:
@ray326May 15.2006 — but by doing this there is no need for client-side restrictions[/QUOTE]Still, doing it on the client, too, usually makes for a better user experience.
Copy linkTweet thisAlerts:
@mark200authorMay 15.2006 — Well I'd prefare to do it server-side. The only problem at the moment is that the people I am currently hosting with has a built-in formMail clone or whatever, and I can't access the script from ftp...this is what it says when i go into the FormMail clone in cpanel:

FormMail Clone is clone of Matt Wright's FormMail under a less restrictive liscense. It should behave almost exactly as FormMail.cgi, but it is completely written from scratch so there might be a few minor visual differences.

The Actual Script is here: http://webtechdublin.com/cgi-sys/FormMail.cgi

The documentation for Matt Wright's FormMail.cgi might be helpful if you have never used FormMail before. It is available [url=http://www.worldwidemart.com/scripts/readme/formmail.shtml]here[/url]. Please note that the CPanel developers are not associated with Matt Wright's Script archive in any way.
[/quote]


How do I edit it....i can not see the cgi-sys directory over ftp......
Copy linkTweet thisAlerts:
@ray326May 15.2006 — You can start here if you can have your own cgi-bin.

http://www.bignosebird.com/carchive/bnbform.shtml
×

Success!

Help @mark200 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...