JavaScript [RESOLVED] Regular Expressions and Javascript Help needed
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: [RESOLVED] Regular Expressions and Javascript Help needed

  1. #1
    Join Date
    Feb 2010
    Posts
    9

    [RESOLVED] Regular Expressions and Javascript Help needed

    In need of some reg exp assistance, I would like to remove all characters from a user's input except for those I designate. I have it working all except if a space is added which I would like to keep. I have included the code I am using below. As you can see, I would like to keep all alphanumerics as well as ?, *, and -. I have tried added \s inside and outside the brackets and the spaces remain; however the end user can use special characters (%, #, &, etc) which I want to disallow.

    document.getElementById("trackingID").value = acctNum.replace(/[^\A-Za-z0-9?*-]/g, "");

    Maybe I am going about this the wrong way and should use something other than a regular expression. I am open for any suggestions

    Thanks in advance.

  2. #2
    Join Date
    Feb 2010
    Posts
    9

    Re: Regular Expressions and Javascript Help needed

    Just an FYI. I was able to fix the issue.

    document.getElementById("trackingID").value = acctNum.replace(/[^\A-Za-z0-9?*\-\s]/g, "");

    The reg exp was using the - as a range instead of a literal. I \-\s at the end and it is keeping the spaces as well as the dash.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center