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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post

    regexp help... only numbers and chars

    Hey,

    I've tried the search on this site and come up with the following

    alert(text.replace(/[^A-z-' ']/g,""));

    but it doesnt seem to work....

    what I need is to allow only characters and numbers in the string, oh and curly braces....

    eg: text = "{hello},"

    I need to strip everything but chars, numbers and { }

    this reg exp thing is a nightmare!!!!
    please some one help!!

  • #2
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    alert(text.replace(/[^\a\d{}]/g))
    might work for you. Liorean's got a couple of great regex tutorials linked from his sig -- check those out.

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    cheers... that seems to strip out all chars apart from "a" ??

    text = "{firstname},";

    alert(text.replace(/[^\a\d{}]/g,''));

    shows

    {a}


  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Choopernikel: Actually, just one article, but from both places it's been publiciced.


    homerUK: text.replace(/[^a-z0-9{}]/gi,'');
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    thanks - works perfectly


  •  

    Posting Permissions

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