RegularExpressionValidator - (.Net 2.0)

Discussion in 'ASP .Net' started by M. Ali Qureshi, Dec 17, 2007.

  1. Hi,

    I have a text field, where i want the user to add only numbers. The minimum
    value should be 1 and there is no limit on maximum value.

    I cannot use RangeValidator, because it requires a maximum value as well.

    Can i use RegularExpressionValidator for this purpose? Could someone give me
    an example of ValidationExpression i should use?

    Thanks in advance.
    M. Ali Qureshi, Dec 17, 2007
    #1
    1. Advertising

  2. You could just write a CustomValidator that checks for an (Integer?) value
    greater than zero.

    http://msdn2.microsoft.com/en-us/library/f5db6z8k.aspx
    -- Peter
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    MetaFinder: http://www.blogmetafinder.com


    "M. Ali Qureshi" wrote:

    > Hi,
    >
    > I have a text field, where i want the user to add only numbers. The minimum
    > value should be 1 and there is no limit on maximum value.
    >
    > I cannot use RangeValidator, because it requires a maximum value as well.
    >
    > Can i use RegularExpressionValidator for this purpose? Could someone give me
    > an example of ValidationExpression i should use?
    >
    > Thanks in advance.
    >
    Peter Bromberg [C# MVP], Dec 17, 2007
    #2
    1. Advertising

  3. M. Ali Qureshi

    marss Guest

    On 17 çÒÄ, 15:16, "M. Ali Qureshi" <> wrote:
    > Hi,
    >
    > I have a text field, where i want the user to add only numbers. The minimum
    > value should be 1 and there is no limit on maximum value.
    >
    > I cannot use RangeValidator, because it requires a maximum value as well.
    >



    What are you going to do with value from the textbox? If you want to
    convert it to a numeric value then a RangeValidator will be good
    enough, just set a maximum value to Int32.MaxValue or Int64.MaxValue
    according to the required result. In that way, you also check whether
    an entered value does not exceed its data type range.

    But if you want a string that contains numbers only, starting from 1,
    use a RegularExpressionValidator with ValidationExpression =
    "[1-9]\d*"

    Regards,
    Mykola
    http://marss.co.ua
    marss, Dec 17, 2007
    #3
  4. You neither need a RegExValidator nor a custom validator for that. The
    compareValidator can validate against a constant value. Your tag should look
    like this:

    <asp:CompareValidator ID="CV1" runat="server"
    Type="Double"
    Operator="GreaterThanEqual"
    ValueToCompare="1"
    ControlToValidate="myTextBox"
    ErrorMessage="Value must be greater than 0!" />

    Hope that works for you. Eid Mubarak ;)

    --
    Mohamad Elarabi
    Lead Developer. MCTS, MCPD.


    "M. Ali Qureshi" wrote:

    > Hi,
    >
    > I have a text field, where i want the user to add only numbers. The minimum
    > value should be 1 and there is no limit on maximum value.
    >
    > I cannot use RangeValidator, because it requires a maximum value as well.
    >
    > Can i use RegularExpressionValidator for this purpose? Could someone give me
    > an example of ValidationExpression i should use?
    >
    > Thanks in advance.
    >
    Mohamad Elarabi, Dec 20, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oleg Ogurok
    Replies:
    1
    Views:
    6,282
    William F. Robertson, Jr.
    Jun 25, 2003
  2. Helixpoint

    RegularExpressionValidator for money??

    Helixpoint, Jun 30, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    2,739
    Helixpoint
    Jul 1, 2003
  3. Salim Afþar

    regularexpressionvalidator numeric control

    Salim Afþar, Aug 4, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    2,557
    Vincent V
    Aug 5, 2003
  4. BH
    Replies:
    0
    Views:
    500
  5. Shan Plourde
    Replies:
    0
    Views:
    3,066
    Shan Plourde
    Jul 19, 2004
Loading...

Share This Page