Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Regular Expressions in .NET

Regular Expressions in .NET

Scheduled Pinned Locked Moved .NET (Core and Framework)
helpcsharpdatabaseregextutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    conrado7
    wrote on last edited by
    #1

    Can anyone help me? I`ve just started my adventure with .NET. I want use regular expression in my text box to validate text. For example reg. expression like this : "[0-9][0-9]-[0-9][0-9][0-9]" accepts only for example "43-456" text. What if I enter "54-8f5" ? .NET Regular Expressions tells me that this text is not correct. But it doesn`t tell me which character is invalid. My problem is that I want .NET show me which character (which character index in this incorrect string) is invalid. Can anyone help with this? conrados

    M C 2 Replies Last reply
    0
    • C conrado7

      Can anyone help me? I`ve just started my adventure with .NET. I want use regular expression in my text box to validate text. For example reg. expression like this : "[0-9][0-9]-[0-9][0-9][0-9]" accepts only for example "43-456" text. What if I enter "54-8f5" ? .NET Regular Expressions tells me that this text is not correct. But it doesn`t tell me which character is invalid. My problem is that I want .NET show me which character (which character index in this incorrect string) is invalid. Can anyone help with this? conrados

      M Offline
      M Offline
      militiaware
      wrote on last edited by
      #2

      I think, and only i think.. that .NET not capable to do that... so you could do it manually... using the string methods and check if the string is numeric or not, then you could run the validation as an expression.... or you could ask the MSDN ...Miliaware ..Faris Madi -- modified at 20:16 Thursday 24th November, 2005

      1 Reply Last reply
      0
      • C conrado7

        Can anyone help me? I`ve just started my adventure with .NET. I want use regular expression in my text box to validate text. For example reg. expression like this : "[0-9][0-9]-[0-9][0-9][0-9]" accepts only for example "43-456" text. What if I enter "54-8f5" ? .NET Regular Expressions tells me that this text is not correct. But it doesn`t tell me which character is invalid. My problem is that I want .NET show me which character (which character index in this incorrect string) is invalid. Can anyone help with this? conrados

        C Offline
        C Offline
        Curtis Schlak
        wrote on last edited by
        #3

        As militiaware writes, the Regex capabilities in .NET do not offer the option to find the place where the Regex fails to match. However, you could write your own regular expression parser to find the "best match" to your string and, then, you will know which character failed. I recommend this book, especially Chapter 8, "Parsing Regular Expressions": Title: Building Parsers With Java ISBN: 0201719622 Though the code and examples are in Java, you can easily translate it to the .NET-supported language of your choice. The design of his parser has a bestMatch() method that will return the string that best matches your given input, in this case, "[0-9][0-9]-[0-9][0-9][0-9]". "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups