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!

Defining how an entry is made

Status
Not open for further replies.

thegiraffe

Programmer
Mar 8, 2002
49
IE
I have come across a problem concerning entry of data into my database.

On the page in question I am taking ct references, vat numbers and other such references that are always entered in a specific way, ie. 3 numeric, space, 2 letters, space, 6 alphanumeric.

Can i do this whilst it is being typed by the user, without to much hastle, i'm not a javascript type person but i'll give it a go if asp/vb can't!

Can i do it as they type or do i have to do it afterwards, or when submitted.

As a previous access writer i know it can be done simply there, can i here!!!

Cheers
Dave

Theres nothing worse than an idea when its the only one we have!
 
You could format it on the OnBlur event.

something like this:

sub myField_onBlur()
dim sValue = document.form(0).myfield.value
if Len(sValue) < 11 then
msgbox &quot;error'
else
document.form(0).myfield.value = Left(sValue,2) & &quot; &quot; & Mid(sValue,3,2) & &quot; &quot; & Right(sValue,6)
end if
end sub



 
Just trying to put this into my page, i'm guessing this checks that it is at least eleven spaces long then theres something about splitting but i'm not sure exactly why or to what avail, is there any formatting as in check if its numeric etc, as i can see all it does is put spaces in, am i wrong?

Ideally i want them to start typing in the box and it kinda goes ___ __ ______ and will only accept numeric in the first three, then 2 letters, then 6 whatever.
Would i have to do this in 3 seperate text boxes with maxlength = 3 and try to format it seperately, then insert them together?

The ideas there but i'm lacking know how

Cheers
Dave

Theres nothing worse than an idea when its the only one we have!
 
The first post was a psuedo outline without using
java script. Basically you could break it down into the 3 parts and then validate them.

Use the IsNumeric Function for the first part.
Then check the values for the next part something like:

if asc(ucase(Mid(sValue,3,1))) < 65 and asc(ucase(Mid(sValue,3,1))) > 90 then do error logic...

It is not the best way of doing what you want but will work.

also...
I found this link for a javascript input mask. may give you a start...

In javascript you could check character by charater and insert spaces as needed.
 
I'm just about out of the door so i'll look at the javascript way in the morning, if i can't get that to work (with my limited intelligence) then i'll use your original plan, i just got a bit lost in code for a bit there

Cheers and i hope i crack it

Dave

Theres nothing worse than an idea when its the only one we have!
 
Right, I have looked at the link and it is good!!

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 &quot;-&quot; or a &quot;:&quot; 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 &quot; &quot;, so i want to return to the field &quot;456 &quot; so the next value entered would appear as &quot;456 P&quot; 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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top