/    Sign up×
Community /Pin to ProfileBookmark

Types Of TextBox Validation + date textbox?

Guys Im calling on your help again.

I need to do some vallidation on text boxes in an asp program Im writing as if everything in the form isn’t entered correctly you cannot continue.

Can you help me with how I do the following verifications:

Check a value entered is of 6,8 or 3 numberical didgits long.

Check any text has been selected

In dropdown menu an item has been selected.

If this has not been done either a simple pop up error message can apear or it would be great if another small pop up html window apeared (which can be cloased) saying re-enter info.

—– ALSO ——-

One of the inputs would be date now I can ask just to enter the nbame in text (as its stored in a string) but the problem is anyone can enter anything and not only just valid dates is it possible to have a button that when you click on it it opens a small calendar where you can select year month and date and this then sends the answer as a string value of DD/MM/YY???

Thanks loads Guys
Any help would be awesome!
Gowans

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@sciguyryanOct 17.2004 — For the first one try somethign like this (Untested):


<i>
</i>var Elm = document.getElementById("Yout textelements ID Here");
if ((typeof eval(Elm.value)) == "number"){
if ((Elm.value.length == 2) || (Elm.value.length == 5) || (Elm.value.length == 7)){
var The_Num = eval(Elm.value);
// Do something here...
}
}



To get the selected item in a dropdown menu you have to do soemthing like this:

<i>
</i>function Check_Select(Elm){
var TheElm = Elm;
var Selected = TheElm.selectedIndex;
if (!Selected){
window.alert("Sorry, you MUST select an element.");
Elm.focus();
return false;
}
else{
return true;
}
}


And as the OnChange event handler for the dropdown menu put this:

OnChange="return Check_Select(this);"

One note, if you have a default selected that method will not work.



And for the final date validation look here for some good ones:

http://www.regexplib.com/


Hope that helps,


RyanJ
Copy linkTweet thisAlerts:
@gowans007authorOct 17.2004 — thanks ryan,

does that code check the same text box for sizes?

I need it to checck the first textbox is equal to 6

the second = 8

thrid = 3

can i just adapt this code for the different ID names?

will this just bring up a message or open a small html pop up?

Ill have an exeperiment with it also.
Copy linkTweet thisAlerts:
@sciguyryanOct 18.2004 — [i]Originally posted by gowans007 [/i]

[B]thanks ryan,



does that code check the same text box for sizes?



I need it to checck the first textbox is equal to 6

the second = 8

thrid = 3



can i just adapt this code for the different ID names?



will this just bring up a message or open a small html pop up?



Ill have an exeperiment with it also. [/B]
[/QUOTE]


Ah, sorry! I missunderstood your question there.

To get more then one element's IDs you'd just create a new variable and assign a document.getElementById() to that element.

To check its value you would just use an IF Statement to ch4eck is value.

To open an alert then check its valuie, if it does not do it correct then use window.alert() to alert the user.

RyanJ
Copy linkTweet thisAlerts:
@gowans007authorOct 22.2004 — Thanks Bud!
Copy linkTweet thisAlerts:
@sciguyryanOct 23.2004 — [i]Originally posted by gowans007 [/i]

[B]Thanks Bud! [/B][/QUOTE]



No problem ?


RyanJ
×

Success!

Help @gowans007 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.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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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