0

I am trying to validate string which can take only alphanumeric values without space.

str.replace(/[^a-zA-Z0-9\u00E0-\u00FC ]+/gi, '')

I used above code but seems still it is taking white space. Did not able to find the right way to fix it.

4
  • 1
    try: str.replace(/[^a-zA-Z0-9\u00E0-\u00FC]+/gi, '') Commented Oct 19, 2015 at 16:34
  • 1
    You put a space in your set of accepted chars so yes, it is taking white spaces. Commented Oct 19, 2015 at 16:36
  • Ohh, I see.. I should not put white space . I was thinking it will take only ascii code. Commented Oct 19, 2015 at 16:37
  • Space is a valid ASCII (and unicode) char. Commented Oct 19, 2015 at 16:37

1 Answer 1

1

Remove the space in regexp

  str.replace(/[^a-zA-Z0-9\u00E0-\u00FC]+/gi, '')
  //  ---------------------------------^ here
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.