Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    simple regex matching help

    Hi, I'm trying to match valid names from a list. Valid names can only contain letters, periods ".", commas "," , spaces " ", and must atleast contain 1 letter.
    Code:
    var checkname =  /[a-zA-Z]+(\.|,|\s)*/;
    but with this regex string, it also matches names that contain letters and numbers. How do I make it to match only what I've mentioned above?
    Any help would be appreciated...

    Thanks

  • #2
    New Coder
    Join Date
    Mar 2010
    Location
    Virginia, USA
    Posts
    25
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Hello.

    I'm guessing by the example you gave that you also want the name to be valid only when it starts with a letter. Here's one way to go about it:

    Code:
    var checkname =  /^[a-zA-Z][a-zA-Z., ]*$/;
    This is assuming that the beginning and ending white-space has already been stripped from the variable you're checking against.

    - C. Aaron Smith

  • Users who have thanked hoothelp for this post:

    akan (03-11-2010)

  • #3
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks, I completely forgot about the start and end anchors..


  •  

    Posting Permissions

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