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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP Form Validation

Status
Not open for further replies.

briggsc

Technical User
Jan 1, 2005
14
US
Hi,

I have a form done in .asp. In this form the user will be asked to
enter an amount. To insure the proper amount is entered, how can I
validate the fields to force the user to enter an increment amount. For
Example, increments of a 100.00 or 2,000.00.


This is what I have so far, but the function keep return False even if
I put in the correct increment amount.


<%Function IsExactMultiple(strToBeTested, intMultipleOf)
IsExactMultiple= False
If IsNumeric(strToBeTested) = False Then Exit Function
If Len(strToBeTested) = 0 Then Exit Function
strToBeTested = CDbl(strToBeTested)
IsExactMultiple= ((strToBeTested MOD intMultipleOf) = 0)
End Function


If IsExactMutilple= true Then
Response.Write("Enter the correct format")
End If


%>

<form>

<input type="text" name="dollar" size="10" value="<%Response.Write
(IsExactMultiple(Request.Form("dollar"), 1000))%>">
<input type="submit">
</form>

Thanks for your help!
 
The MOD will return null, 0, or the remainder I don't think it will return a true or false. Maybe try setting the following:

IsExactMultiple = (strToBeTested MOD intMultipleOf)

and then test as such:

if not isnull(IsExactMultiple) and IsExactMultiple <> 0 then
Response.Write("Enter the correct format")
End If


Hope this helps.
 
Thanks so much for your help!

I tried your code, but I get a Wrong number of arguments or invalid property assignment error message on the if not isnull(IsExactMultiple) and IsExactMultiple <> 0 then.

Thanks Again for your help!
 
If IsExactMutilple= true Then
Response.Write("Enter the correct format")
End If


In the above if test you have typoed. You have IsExactMutilple but it should be IsExactMultiple.
 
Thank again for your help!

I caught that typo earlier and changed it, but it still did the same.

Now, I've changed the code and it's show False again whether If I put in the correct increment amount or not.

I'm sorry if I am taking too much of your time.
 
Hello briggsc,

[1] Your function is by itself ok. Only, you have to know the functioning of it.

[1.1] The mod function performs implicit type casting making the two arguments integers. For instance,
(10.5 mod 10.1) result = 0
You then might take 10.5 at its face value.

[1.2] Know the effect of printable and/or control characters get into it. For instance isnumeric() results in true for "10.5" & chr(10), but false for "10.5" & chr(50). Nonetheless, both these fictitious string once cdbl() result both 10.5.

[2] As to debug, check if all the false result from the first screening, ie isnumeric() or not. Put some response write to differentiate the position of exit function.

[3] Your form section makes the whole question problematic. Where do you put thee form? It is part of the calling page? or it is the response asp page? Why you want to put true or false in a text input with name "dollar", on the surfacing, contradict to your design intention? Just can't figure out. But, you know better...

regards - tsuji
 
Hi Tsuji,

Thanks for your help! The form will be on the same page of the asp page. I am fairly new to asp programming and need all the help I can get. What I basiclly whant is to validate the form field. There will be a note next to the field that says enter amount in 200 or 1000 increments. I want the form produce an error if the amount is not the increment amount. I don't want to put the true and false inthe form field. I couldn't figure out where should I put the coding. Where would you put it?

Thanks again for your help and your time!
 
briggsc,

How about validating on the client-side before submitting? In the private network environment, you can keep using vbs if msie is the browser, else you might have to consider the equivalent javascript transciption of the same functionality. And it relies on the user allowing active scripting.

- tsuji
 
Actually this is for a private network environment. Microsoft Internet Explorer is the only browser we use. I'm not very knowledgable with Javascript, but I'll look into it. I wanted to use server side vbs script because all of my other validation code is in that script.

Again, Thanks for your help and time!
 
briggsc,

It is for sure validation server-side is of more certainty. Even you implement a client-side validation to reduce the traffic, server-side validation is still needed as a final defense to make sure you accept the correct data.

In any way, the setting as shown in your original posting, with expansion, is probably being used to return the page for client to correct their mistake? Else, you can't possibly validate anything before submit? You know better...

- tsuji
 
Hi Tsuji,,

I've got it to work. Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top