Svante
AxCrypt - Free Open Source File Encryption & Online Password Manager - http://www.axantum.com [Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.
The ASP.NET Validator controls will perform it's validation both in JavaScript on the client, and on the server, so that way you get the best of both worlds without any extra effort. If you use the code linked to, please note that it also makes use of a
Validator control (which unless you stop it, will actually perform the test in JavaScript as well - so you get two client-side validations and one server-side validation).
It's ok to do JavaScript validation - but never only JavaScript validation. You must always do server-side validation at least. JavaScript validation is an extra usability bonus, but your code must never depend on that validation actually being performed.
Any user may have turned off JavaScript in their browser, and a malicious user will most certainly do so to try to make your code do things you don't want it to do.
Svante
AxCrypt - Free Open Source File Encryption & Online Password Manager - http://www.axantum.com [Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.
The ASP.NET Validator controls will perform it's validation both in JavaScript on the client, and on the server, so that way you get the best of both worlds without any extra effort. If you use the code linked to, please note that it also makes use of a
Validator control (which unless you stop it, will actually perform the test in JavaScript as well - so you get two client-side validations and one server-side validation).
It's ok to do JavaScript validation - but never only JavaScript validation. You must always do server-side validation at least. JavaScript validation is an extra usability bonus, but your code must never depend on that validation actually being performed.
Any user may have turned off JavaScript in their browser, and a malicious user will most certainly do so to try to make your code do things you don't want it to do.
neon2
ok with validator controls it works fine. I can only numeric data, but i want to specify it decimal lenth ,
can it be done ?
hi neon2.. i think there is a slight misunderstanding.. i think the reply in above post by
Svante is for another post named as... difference between asp validation and javascript validation.
Yes. You can use multiple validator controls, for example one RangeValidator to check that it's within a certain range etc, and a RegularExpressionValidator to check for a given pattern. You can also write a CustomValidator, which can do any kind of test
you want. In this case I think you'll be fine with a RegularExpressionValidator. The following will validate numbers like 0, 12, 12.0, 12.34 but not A, 12A, 12.1234 etc:
@"[0-9]+(\.[0-9]{1,2}){0,1}"
(I think.. I have not tried it.) The idea is:
[0-9] matches any digit. the following '+' says match 1 or more digits.
followed by what's inside the ( ) which can occurr 0 or 1 times (that's the {0,1} at the end.
Inside the parenthesis we have:
\. which means a literal dot. The backslash escapes it, otherwise . matches any character.
[0-9] again, now 1 or 2 times, that's the {1,2}.
Svante
AxCrypt - Free Open Source File Encryption & Online Password Manager - http://www.axantum.com [Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.
i think the reply in above post by
Svante is for another post named as... difference between asp validation and javascript validation.
Hi, actually no it was in reply to the link you provided. I wanted to point out that the code there probably does the job, but it does appear to do it twice more or less, and I also wanted to point out the extreme importance of not trusting client side validation
- but to just view it as a user convenience. The RegularExpressionValidator should be enough - it'll do both client-side and server-side validation.
Svante
AxCrypt - Free Open Source File Encryption & Online Password Manager - http://www.axantum.com [Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.
neon2
Member
44 Points
48 Posts
numeric text box
Sep 14, 2007 06:16 AM|LINK
hello friends,
please tell me who can i develop a new numeric text box control that will only accepts numeric value.
Thanks In advance
Neon2
Svante
All-Star
18347 Points
2300 Posts
Re: numeric text box
Sep 14, 2007 06:26 AM|LINK
Hello,
This type of task is typically performed using validators. You don't need a custom control. Please see for example http://msdn2.microsoft.com/en-us/library/ad548tzy.aspx .
AxCrypt - Free Open Source File Encryption & Online Password Manager - http://www.axantum.com
[Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.
kaushalparik...
All-Star
26580 Points
3693 Posts
MVP
Re: numeric text box
Sep 14, 2007 06:45 AM|LINK
Numeric TextBox for ASP.NET
NumericValidator Source Code
hope it helps./.
[KaushaL] || BloG || Twitter
Don't forget to click "Mark as Answer" on the post that helped you.
neon2
Member
44 Points
48 Posts
Re: numeric text box
Sep 14, 2007 07:55 AM|LINK
thanks friends,
I do want to do it in java script, so kaushalparik27 link help me a lot.
Now can i mention decimal like 2 or 3 for the numeric box.
Svante
All-Star
18347 Points
2300 Posts
Re: numeric text box
Sep 14, 2007 09:19 AM|LINK
The ASP.NET Validator controls will perform it's validation both in JavaScript on the client, and on the server, so that way you get the best of both worlds without any extra effort. If you use the code linked to, please note that it also makes use of a Validator control (which unless you stop it, will actually perform the test in JavaScript as well - so you get two client-side validations and one server-side validation).
It's ok to do JavaScript validation - but never only JavaScript validation. You must always do server-side validation at least. JavaScript validation is an extra usability bonus, but your code must never depend on that validation actually being performed. Any user may have turned off JavaScript in their browser, and a malicious user will most certainly do so to try to make your code do things you don't want it to do.
AxCrypt - Free Open Source File Encryption & Online Password Manager - http://www.axantum.com
[Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.
neon2
Member
44 Points
48 Posts
Re: numeric text box
Sep 14, 2007 10:28 AM|LINK
ok with validator controls it works fine. I can only numeric data, but i want to specify it decimal lenth ,
can it be done ?
kaushalparik...
All-Star
26580 Points
3693 Posts
MVP
Re: numeric text box
Sep 14, 2007 10:33 AM|LINK
hi neon2.. i think there is a slight misunderstanding.. i think the reply in above post by Svante is for another post named as... difference between asp validation and javascript validation.
[KaushaL] || BloG || Twitter
Don't forget to click "Mark as Answer" on the post that helped you.
Svante
All-Star
18347 Points
2300 Posts
Re: numeric text box
Sep 14, 2007 10:37 AM|LINK
Yes. You can use multiple validator controls, for example one RangeValidator to check that it's within a certain range etc, and a RegularExpressionValidator to check for a given pattern. You can also write a CustomValidator, which can do any kind of test you want. In this case I think you'll be fine with a RegularExpressionValidator. The following will validate numbers like 0, 12, 12.0, 12.34 but not A, 12A, 12.1234 etc:
@"[0-9]+(\.[0-9]{1,2}){0,1}"
(I think.. I have not tried it.) The idea is:
[0-9] matches any digit. the following '+' says match 1 or more digits.
followed by what's inside the ( ) which can occurr 0 or 1 times (that's the {0,1} at the end.
Inside the parenthesis we have:
\. which means a literal dot. The backslash escapes it, otherwise . matches any character.
[0-9] again, now 1 or 2 times, that's the {1,2}.
AxCrypt - Free Open Source File Encryption & Online Password Manager - http://www.axantum.com
[Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.
kaushalparik...
All-Star
26580 Points
3693 Posts
MVP
Re: numeric text box
Sep 14, 2007 10:39 AM|LINK
hi there.. you can modify below regular expressin accodring to your need... the regex below will allow 5 digits with 2 decimal points
you will find more regex options at: Regular Expression Library
and for numeric data: http://regexlib.com/DisplayPatterns.aspx?cattabindex=2&categoryId=3
hope it helps./.
[KaushaL] || BloG || Twitter
Don't forget to click "Mark as Answer" on the post that helped you.
Svante
All-Star
18347 Points
2300 Posts
Re: numeric text box
Sep 14, 2007 10:42 AM|LINK
Hi, actually no it was in reply to the link you provided. I wanted to point out that the code there probably does the job, but it does appear to do it twice more or less, and I also wanted to point out the extreme importance of not trusting client side validation - but to just view it as a user convenience. The RegularExpressionValidator should be enough - it'll do both client-side and server-side validation.
AxCrypt - Free Open Source File Encryption & Online Password Manager - http://www.axantum.com
[Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.