Validate regular expresion - TextField

  1. #1

    Validate regular expresion - TextField

    Hi,

    I had a problem with the regex property of the TextField.

    If I do:

    
    
    
    <ext:TextField ID="txtDiscount" Width="120" runat="server" Regex="[1][0][0]|[0-9]{1,2}(\.[0-9]{1,2})?"  RegexText="Invalid format" />
    the validate is incorrect.

    I've tried to do the next:

    
    
    
    <ext:TextField ID="txtDiscount" Width="120" runat="server" />
    
    
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="txtDiscount" ValidationExpression="[1][0][0]|[0-9]{1,2}(\.[0-9]{1,2})?" runat="server" ErrorMessage="Invalid format"></asp:RegularExpressionValidator>
    and it found correcty.


    I hope It cans be useful.

    Best wishes.

  2. #2

    RE: Validate regular expresion - TextField

    Can you give me a couple examples of values you would like to accept?
  3. #3

    RE: Validate regular expresion - TextField

    Sure,

    the regular expresion must be validate a range [0-100]

    For example:

    100, 25.50, 64, etc...

    An incorrect value:

    100.36, 45454, etc...

  4. #4

    RE: Validate regular expresion - TextField

    I would use the following:

    <asp:RangeValidator runat="server" ... MaximumValue="100" MinimumValue="1" Type="Currency" />
    Cheers,
    Timothy
  5. #5

    RE: Validate regular expresion - TextField

    Thank you for your reply, Timoty, but I don't want use an asp control because all controls of my page are coolite controls.

    I use the property with other regular expresion (e-mail format, time format, etc...) and found correctly but I don't know why this regular expresion fail.

    I used the asp:regularExpresionValidator control only to try if it was correct or not.




  6. #6

    RE: Validate regular expresion - TextField

    Hmm, looks to be like your regular expression was missing some stuff:

    <ext:TextField ID="txtDiscount" Width="120" runat="server" Regex="^(100|([1-9][0-9]{0,1}(\.[0-9]{2})?))$"  RegexText="Invalid format" />
    Works for me.
  7. #7

    RE: Validate regular expresion - TextField

    If you're dealing with currency, the following might be helpful, see http://forums.ext.net/showthread.php...-1.aspx#bm4991

    Geoffrey McGill
    Founder
  8. #8

    RE: Validate regular expresion - TextField



    Thanks, Timothy and geoffrey.mcgill.

    I apologize for the trouble. I've forgotten to indicate the start condition with the "^" symbol.

    But I don't understan why it's happening because by means of
    others ways (asp validation controls, regex library, etc...) the previous regular expresion founds correctly. Is coolite more strict?





    Thanks a lot :)


  9. #9

    RE: Validate regular expresion - TextField

    Hello Kaido,

    I would say that Coolite and ExtJS are using the regular expressions properly, and not that they are strict. I think Microsoft ASP.NET regular expressions are a little "candy coated" for first time regular expression users, so they will easily forgive you if you're missing your ^ $ characters ;)

    Hope this all worked out for you.

    Cheers,
    Timothy
  10. #10

    RE: Validate regular expresion - TextField

    Hi, Timothy

    You're absolutely right :) From now on, I will never forget to specify this characters.


    Thank you so much ^^

Similar Threads

  1. Replies: 3
    Last Post: Jun 11, 2013, 4:48 AM
  2. Replies: 1
    Last Post: Mar 16, 2010, 10:28 AM
  3. Replies: 1
    Last Post: Mar 12, 2010, 6:18 PM
  4. [CLOSED] validate textfield on blur
    By idrissb in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Aug 29, 2009, 3:47 PM
  5. Update grid with Regular ADO.NET
    By sharif in forum 1.x Help
    Replies: 0
    Last Post: Jul 07, 2009, 8:19 AM

Posting Permissions