473,508 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check textbox value...

NH
How can I check the value of a textbox has no more than 2 decimal places?

I already check that the value is numeric, but how do I check that it is not
0.223 or .022 etc. I only want to allow up to 2 decimal places...
Jan 5 '06 #1
3 3259
Turn it into a string, and look at the position of the decimal point in the
string.
If it's more then the 3rd character from the end, then there are too many
decimal points.

"NH" <NH@discussions.microsoft.com> wrote in message
news:C2**********************************@microsof t.com...
How can I check the value of a textbox has no more than 2 decimal places?

I already check that the value is numeric, but how do I check that it is
not
0.223 or .022 etc. I only want to allow up to 2 decimal places...

Jan 5 '06 #2
A regular expression to check for a number with 2 decimals looks like this
"^(\+|-)?\d{1,6}(\.\d{1,2})?$". You may use it in a
RegularExpressionValidator:

<asp:TextBox ID="txtNumber" Runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="valTxtNumber"
ControlToValidate="txtNumber" Runat="Server" ValidationExpression
="^(\+|-)?\d{1,6}(\.\d{1,2})?$" ErrorMessage="Number is not valid. Please
enter numbers with 2 decimals only" > </asp:RegularExpressionValidator>

Or you may use it in a Javascript like this:
var re = /^(\+|-)?\d{1,6}(\.\d{1,2})?$/g;
alert(re.test("123456.123")); //this will echo false
alert(re.test("56.23")); //this will echo true

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"NH" wrote:
How can I check the value of a textbox has no more than 2 decimal places?

I already check that the value is numeric, but how do I check that it is not
0.223 or .022 etc. I only want to allow up to 2 decimal places...

Jan 5 '06 #3
NH
Thanks for your suggestions, Philips looks like the one to use.

Regards
N

"Phillip Williams" wrote:
A regular expression to check for a number with 2 decimals looks like this
"^(\+|-)?\d{1,6}(\.\d{1,2})?$". You may use it in a
RegularExpressionValidator:

<asp:TextBox ID="txtNumber" Runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="valTxtNumber"
ControlToValidate="txtNumber" Runat="Server" ValidationExpression
="^(\+|-)?\d{1,6}(\.\d{1,2})?$" ErrorMessage="Number is not valid. Please
enter numbers with 2 decimals only" > </asp:RegularExpressionValidator>

Or you may use it in a Javascript like this:
var re = /^(\+|-)?\d{1,6}(\.\d{1,2})?$/g;
alert(re.test("123456.123")); //this will echo false
alert(re.test("56.23")); //this will echo true

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"NH" wrote:
How can I check the value of a textbox has no more than 2 decimal places?

I already check that the value is numeric, but how do I check that it is not
0.223 or .022 etc. I only want to allow up to 2 decimal places...

Jan 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2546
by: buran | last post by:
Dear ASP.NET Programmers, I have a question about a script I'm trying to code and invoke when a button (btnSave) is pressed on the page. This script should only run when a textbox (txtAD) on the...
2
3088
by: Kiran | last post by:
Hi, How can I check whether the value entered in a textbox is numeric without doing a postback Kiran
1
1546
by: d9pierce | last post by:
Hi all, I have a company form that I would like to protect against duplication unless checked. Main point being, that I dont want to just be able to add a duplicate company name in a test box...
0
887
by: Jay Kudecha | last post by:
Hi All, I am preparing a .Net deployment project, where i need to get some data from the user. I have added custom textbox dialog in Installer which has one textbox visible where the user has to...
20
14354
by: technocraze | last post by:
Hi guys & commnunity experts, Does anyone knw how to go about checking for existing data in an MS Acess table? I have tried out the following code using vb but doesnt seem to work that well? Can...
2
7115
by: DesCF | last post by:
I have a textbox and a combobox on a toolstrip. The user enters either an ID in the textbox or selects a name from the combobox. When the user selects a name from the combobox the textbox is...
2
9124
by: wildman | last post by:
RE: Gridview textbox has data check without postback.. javascript? I have a gridview with a textbox. I can set the textbox to autopostback and check for a value in a prerender event to decide if...
7
2839
by: billa856 | last post by:
Hi, My project is in MS Access 2002. In that I have two forms which I am using for Shipping Entry. Now First Form(ShippingAlerts) Is fillup by persons working in customer services.and the Second...
2
983
by: sweatha | last post by:
Hi friends This is Sweatha. My problem is, I have created the Registration Form with one LabelBox as Label1 one TextBox as TextBox1 & one Button as Button1. Then I have generated the random...
0
7226
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7125
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7388
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7049
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3199
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
422
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.