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... 3 3307
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******** *************** ***********@mic rosoft.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...
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
RegularExpressi onValidator:
<asp:TextBox ID="txtNumber" Runat="server"> </asp:TextBox>
<asp:RegularExp ressionValidato r ID="valTxtNumbe r"
ControlToValida te="txtNumber" Runat="Server" ValidationExpre ssion
="^(\+|-)?\d{1,6}(\.\d{ 1,2})?$" ErrorMessage="N umber is not valid. Please
enter numbers with 2 decimals only" > </asp:RegularExpr essionValidator >
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...
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 RegularExpressi onValidator:
<asp:TextBox ID="txtNumber" Runat="server"> </asp:TextBox> <asp:RegularExp ressionValidato r ID="valTxtNumbe r" ControlToValida te="txtNumber" Runat="Server" ValidationExpre ssion ="^(\+|-)?\d{1,6}(\.\d{ 1,2})?$" ErrorMessage="N umber is not valid. Please enter numbers with 2 decimals only" > </asp:RegularExpr essionValidator >
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... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 page is left blank. I tried to use a code snippet with the
"return confirm" function but without success. The code should check whether
the textbox is empty or not, and if empty, it should ask the user to
continue and then run the next code. How...
|
by: Kiran |
last post by:
Hi,
How can I check whether the value entered in a textbox is numeric without
doing a postback
Kiran
|
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 unless I need that for some
reason, which there are reasons. I need a bound or unbound check box
that would be clicked to cheeck for duplicate records once i type in a
company name and leave that field. I need this to be able to view that
company...
|
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 write "Product Code" in it.
Now i need to check whether the Product code inserted by user is same with the actual product code or not.
How do i check the whether both values are same or not?
If both values are not same, i need to cancel the...
|
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 anyone ps take a look at this code / logic and if possible point out the error or make correction?
What i need is to check for existing studentId and name before insertion. If the inserted value existed in the table, message "duplicate" else...
| |
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 filled in automatically by
setting its .Text property equal to the .SelectedValue of the combobox.
When the user enters an ID in the textbox the combobox's .SelectedValue is
set to the .Text value in the ID textbox. All works fine but it is ...
|
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 I
should make a button on the grid row visible. However, the problem
with autopostback on a textbox is the postback occurrs when you select
another control or click away ( I guess). This is very awkward when
the control selected is dropdown as...
|
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 Form(ShippingEntry) is fillup by workers operating Hi-Low machines to put Boxes in Trucks.
Now In First Form(ShippingAlerts)I have some fields like
AutoNo,BillToAddress,ShipToAddress. and some other like
CustomerCode,ItemNo,PONo,LONo,PalletNo...
|
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 numbers by writing the WebMethod in Web Service as
<WebMethod()> Public Function random1() As Double
Dim Rand As New Random
Dim i As Double
i = Rand.NextDouble
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |