Share via


Regular Expression Validator for a Decimal value

Question

Tuesday, October 9, 2012 7:08 PM

I have a textbox for a decimal value like 1.0, 1.1, 1.2, ..., 1.10, 1.11, 1.12...

I use the Regular Expression Validator ^[1-9]+\[0-9][0-9]$ I have also tried ^(d*\\d\d+)$

But both of them allow one decimal (1.1), so in the data base field the system stores 1.10, because the data type is Decimal(18,2).

How can I set the Regular Expression Validator to allow only two decimals mandatory, no less no more (1.01, 1.02, ..., 1.10, 1.11, ...)

If there's a better solution I would apreciate it.

 

All replies (3)

Tuesday, October 9, 2012 8:45 PM âś…Answered

Hi

if you want to decimal places i think you can modify it like this

^[1-9]+\[0-9]{2}$

I think this will work.But i have not tested it yet.

Kind Regards

Ranjeet


Tuesday, October 9, 2012 8:42 PM

try putting () around each required section of regex like

^([1-9])(+\)([0-9])([0-9]$)


Tuesday, October 9, 2012 11:47 PM

Use MaskedEdit - http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/MaskedEdit/MaskedEdit.aspx

<asp:TextBox ID="TextBox1" runat="server" /> 
<cc1:MaskedEditExtender ID="MaskedEditExtender1" runat="server" TargetControlID="TextBox1" 
                        Mask="9{9}.99" MaskType="Number" InputDirection="RightToLeft" />