Regular Expression to enforce format?

Discussion in 'ASP .Net' started by =?Utf-8?B?Qw==?=, Jun 29, 2007.

  1. Hi,

    I have an asp.net textbox and I want to enforce that the user inputs values
    in the following format 1498159\102

    How can I do this using a Regular Expression or otherwise?

    Any advice appreciated.
     
    =?Utf-8?B?Qw==?=, Jun 29, 2007
    #1
    1. Advertising

  2. Here's your regular expression:

    "1498159\102"

    Since "1498159\102" is the format, "1498159\102" is the regular expression.
    Any input that does not match that format will not pass.

    Of course, now you're shaking your head, and thinking what a dumb jerk I am.
    Well, let me plead my case:

    "1498159\102" is not a format. It is a string. A regular expression
    identifies patterns in strings. A pattern is defined by a set of rules
    regarding sequences of characters, rather than a set of literal character
    values. The rules of the pattern indicates what constitutes a matching
    sequence of characters. The regular expression is a shorthand syntax for the
    rules themselves. It may include literal characters and/or pattern tokens.
    Like anything else in computing, the rules are specific and exact, and can
    describe character types, character values, ranges of character values,
    relationships of characters and character sequences to other characters and
    character sequences, quantities of characters and sequences, conditional
    logic, position of characters and sequences, etc.

    So, while a regular expression can be used to derive whether a literal
    string is a match for a pattern, a literal string can not be used to derive
    a regular expression that contains rules that match the string.

    For example, the following regular expressions will match your string:

    ..* (any number of any character)
    \w+.\d{3} (1 or more alphanumeric characters, followed by any single
    character, followed by 3 digits)
    \d{6,}\\102 (6 or more digits, followed by a backslash, followed by the
    sequence "102"

    I hope you get my point. Can you explain the rules you want to use?

    --
    HTH,

    Kevin Spencer
    Microsoft MVP

    Printing Components, Email Components,
    FTP Client Classes, Enhanced Data Controls, much more.
    DSI PrintManager, Miradyne Component Libraries:
    http://www.miradyne.net


    "C" <> wrote in message
    news:...
    > Hi,
    >
    > I have an asp.net textbox and I want to enforce that the user inputs
    > values
    > in the following format 1498159\102
    >
    > How can I do this using a Regular Expression or otherwise?
    >
    > Any advice appreciated.
    >
     
    Kevin Spencer, Jun 29, 2007
    #2
    1. Advertising

  3. On Jun 29, 2:37 pm, "Kevin Spencer" <> wrote:
    > Here's your regular expression:
    >
    > "1498159\102"
    >


    small correction

    ^1498159\\102$
     
    Alexey Smirnov, Jun 29, 2007
    #3
  4. Ah yes, thanks Alexey!

    --
    HTH,

    Kevin Spencer
    Microsoft MVP

    Printing Components, Email Components,
    FTP Client Classes, Enhanced Data Controls, much more.
    DSI PrintManager, Miradyne Component Libraries:
    http://www.miradyne.net

    "Alexey Smirnov" <> wrote in message
    news:...
    > On Jun 29, 2:37 pm, "Kevin Spencer" <> wrote:
    >> Here's your regular expression:
    >>
    >> "1498159\102"
    >>

    >
    > small correction
    >
    > ^1498159\\102$
    >
     
    Kevin Spencer, Jun 29, 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. VSK
    Replies:
    2
    Views:
    2,311
  2. Niclas

    UK Date Format Regular Expression

    Niclas, Dec 2, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    6,982
    Niclas
    Dec 2, 2005
  3. ThunderMusic

    Regular expression, how can I format it?

    ThunderMusic, Feb 2, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    2,177
    =?Utf-8?B?VEg=?=
    Feb 2, 2006
  4. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    852
    Alan Moore
    Dec 2, 2005
  5. GIMME
    Replies:
    3
    Views:
    11,978
    vforvikash
    Dec 29, 2008
Loading...

Share This Page