Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate while typing

Status
Not open for further replies.

thegiraffe

Programmer
Mar 8, 2002
49
IE
I have got some code that validates a string from an input mask,
# for numbers, ? for letters & ! for everything else.
Can anyone help me with the following, i originally posted this in asp and slowly realised i need javascript so i've sneaked in here!

I'm going to use the function from the example and i'm going to attempt to do an onkeyup function call for an input.

The plan!!
Specify a hidden mask for a field to pass in the function.
Have an entry field that has an onkeyup function bolted to it.
For this i will use the previous defined mask ### ?? !!!!!! for a collection reference. I want to specify a mask each time as i don't want to have to recreate a function for every pre defined entry in my form.

I want to validate each value entered such as
entered value: 4
now - pass both the value(4) and the mask to the function,
Calculate entered value length (1)
Select first 1 value from mask, #, which in this case is right, good start!!!

Now, this may sound stupid but at this point i want to check if next value in the mask is a space, or for other masks maybe a "-" or a ":" just for an example.
in this case its another # so i'll get onto this in about two characters!!!!
Anyway i want to return this to the field.

so i repeat this for each character ie, if the entered value is 453 it is each time just checking the last entered value rather than all of them each time!

Now, going back to the space, if i'm on 456 the next value in the mask is " ", so i want to return to the field "456 " so the next value entered would appear as "456 P" kind of thing.

Not only this if the length entered is greater than that of the mask i want an error,
And if keypress is delete i want to skip validation!

I'm new to javascript (if it wasn't that apparent) so any help, much appreciated!
Dave

Theres nothing worse than an idea when its the only one we have!
 
My eyes hurt. Make your questions shorter.

If you want something that verifies text being entered in an input field as the user is typing it then go to :


click on the keez link on the right.

Grab the source code, adapt it to your sauce and have fun.

If it isn't exactly what you want I recommend taking a look at regular expression and adapting the keez script to take them into consideration.

Hope this helps. Gary Haran
 
I like the code, but for me to do that i would have to take the value in 3 seperate boxes (in this example, there is more to it), i have looked into this as an alternative but i'd rather only do this as a last resort.

Its for tax references and stuff and the simple muppets who use the system here struggle to turn their computer on let alone enter things right.

I already have some code that validates a whole string to a mask, i just want to take it one step at a time!

If anyone has any further ideas these are valuable!
Dave

Theres nothing worse than an idea when its the only one we have!
 
Have you tried doing this in VB.net it makes it extremely easy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top