Closed Thread Icon

Topic awaiting preservation: Form Text Field That Allows Only Author-Specified Input Pages that link to <a href="https://ozoneasylum.com/backlink?for=7971" title="Pages that link to Topic awaiting preservation: Form Text Field That Allows Only Author-Specified Input" rel="nofollow" >Topic awaiting preservation: Form Text Field That Allows Only Author-Specified Input\

 
Author Thread
sdna2k
Bipolar (III) Inmate

From: Plano, TX
Insane since: Jun 2001

posted posted 12-07-2001 15:12

I coded this JavaScript to allow you to specify which characters can be entered into a form text field, so that users will have a harder time entering invalid characters for certain fields (such as entering a letter or hyphen into a phone number field, where only numeric is appropriate). I hope it's helpful.

** The variable "vInc" contains the allowed characters **

** The only character that cannot be excluded using this script is the delimiting backslash, "\" **

<!-- Paste one of these three pieces of code into your HEAD tag area -->

** Or modify one to suit your tastes **

** This one allows only numeric input **

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var vInc = /[0\\1\\2\\3\\4\\5\\6\\7\\8\\9\\/]/;
function checkit(val) {
var strPass = val.value;
var strLength = strPass.length;
var lchar = val.value.charAt((strLength) - 1);
if(lchar.search(vInc) == -1) {
var tst = val.value.substring(0, (strLength) - 1);
val.value = tst;
}}
// End -->
</script>

** This one allows only upper and lowercase letters **

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var vInc = /[A\\a\\B\\b\\C\\c\\D\\d\\E\\e\\F\\f\\G\\g\\H\\h\\I\\i\\J\\j\\K\\k\\L\\l\\M\\m\\N\\n\\O\\o\\P\\p\\Q\\q\\R\\r\\S\\s\\T\\t\\U\\u\\V\\v\\W\\w\\X\\x\\Y\\y\\Z\\z\\']/;
function checkit(val) {
var strPass = val.value;
var strLength = strPass.length;
var lchar = val.value.charAt((strLength) - 1);
if(lchar.search(vInc) == -1) {
var tst = val.value.substring(0, (strLength) - 1);
val.value = tst;
}}
// End -->
</script>

** This one allows only time-related input **

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var vInc = /[0\\1\\2\\3\\4\\5\\6\\7\\8\\9\\ \\a\\A\\p\\P\\m\\M\\:]/;
function checkit(val) {
var strPass = val.value;
var strLength = strPass.length;
var lchar = val.value.charAt((strLength) - 1);
if(lchar.search(vInc) == -1) {
var tst = val.value.substring(0, (strLength) - 1);
val.value = tst;
}}
// End -->
</script>

<!-- Paste this piece appropriately into the BODY area of the page -->

<form name="ThisForm" method="post" action="WhateverPage.html">
<input type="text" name="ThisField" size="35" maxlength="20" value="" onKeyUp="javascript:checkit(ThisForm.ThisField);">
</form>

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 12-07-2001 21:07

IMHO Using regular expressions to validate form input is more efficient... Example can be found here: http://www.max.co.yu/ozone/form_validation.html


hlaford
Bipolar (III) Inmate

From: USA! USA! USA!
Insane since: Oct 2001

posted posted 12-07-2001 23:58

I've built something that handles this. Use the whole things or just the FILTER part of it. It's written using regexes.

http://groups.yahoo.com/group/validation/files/Cross-browser/validation.3.0.0b2.zip

I have 3.0.0 final in the works. Here's to hoping the job lets up enough.

Petskull
Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 12-08-2001 00:12

I just have my CGI script yell at 'em

tskull@hotmail.com">
"A kleptomaniac is a person who helps himself because he can't help himself." --Henry Morgan
ICQ: 67751342

Dark
Neurotic (0) Inmate
Newly admitted
posted posted 12-08-2001 00:48

Well ... I think I got to see all your sigs rotating Pet, all of them sweet and high quality.
I still like the grim one though

kars10
Bipolar (III) Inmate

From: Europe
Insane since: Mar 2001

posted posted 12-17-2001 11:28

dud, max,
something is wrong with your validation thingy thing.
My IE wants to start the debbuger because of an "Laufzeitfehler"
just wanted to point that out....
k10

every1 with psycho10esis raise my hand

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 12-17-2001 20:01

It works fine for me... Anyway, by Laufzeitfehler (German) you mean program execution error, right? Did your IE crash when you tried to view that page? If it crashed the problem may be located somewhere else and not in my page...


« BackwardsOnwards »

Show Forum Drop Down Menu