Results 1 to 5 of 5

Thread: Regular Expressions

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2009
    Posts
    116

    Regular Expressions

    I want to create Regular Expression for phone number and valid digits allowed are (,),-,+,0----9. If the left bracket ( is there,then its necessay that right bracket is also there. How to create the Regular Expression for the above. I dont know how to create the regular Expression,they just kill me.

  2. #2
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: Regular Expressions

    hay,
    this will return true,

    Code:
     string phoneNumber = "444-6666";
     bool val = System.Text.RegularExpressions.Regex.IsMatch(phoneNumber, "^[0-9,()+-]{8,12}$");
    if you just write the formula that you want for the phone i think i can help
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Regular Expressions

    Hey,

    Check the link in my signature, there are a number of Regex related links in it.

    Specifically, Regex Lib, it has a own library of Regular Expressions, so it is likely that you will find the one that you need there.

    You might also want to check this out:

    http://gskinner.com/RegExr/

    A very helpful online regular expression checker.

    Hope that helps!

    Gary

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2009
    Posts
    116

    Re: Regular Expressions

    HI avrail, I want the following validations to apply -
    (0124) - 900000
    (91) + 78777
    If I use ur code and write (1234) - 7878 in textbox I am getting false. I want that if the number is in the format as above,it will return true.. and one thing more I have to limit the numbers entered are just 10 exclusing () + -

  5. #5
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: Regular Expressions

    hay mansi,
    sorry i wasn't here

    Code:
    string phoneNumber = "(0123) - 123456";
            bool val = System.Text.RegularExpressions.Regex.IsMatch(phoneNumber
                , @"^(\(\d{2}\)\s?[-|+]\s?\d{5,6}|\(\d{4}\)\s?[-|+]\s?\d{5,6})$");
    Last edited by avrail; Oct 5th, 2010 at 01:00 PM.
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width