-2

I keep trying everything from the search result (google) but without success till now. For my username input I want only to allow alphanumerics, without empty spaces and no tabs. The username can have a combination of letters and numbers, but must have at least one character. Can someone please share a regex able to do that, and with a bit explanation if some changes are required to be made later on.

Thank you in advance.

edit: examples what should be allowed:"a012", "2342a", "anyalpha", "abc2xyz". what should not be allowed: "1234123", " ace12", "any space", "space2 ", " space3"

Tinaira
  • 727
  • 2
  • 7
  • 23
  • it allows combination of numbers without alphabets – Tinaira Feb 27 '19 at 21:44
  • `\D+\S` maybe something like this? – demo Feb 27 '19 at 21:52
  • when you say "it must have at least one character" do you mean one alphanumeric character, or one alphabetic character? – Richard II Feb 27 '19 at 21:53
  • 1
    You should probably include examples of input that is allowed and not allowed. The answers you are getting already demonstrates that your question is unclear about what is meant by "character". – Richard II Feb 27 '19 at 22:04

2 Answers2

1

Try Regex: ^(?=\w*[A-Za-z])\w*$

Demo

Matt.G
  • 3,586
  • 2
  • 10
  • 23
0

Try this regex => ^[A-Za-z0-9]+$

^ start of line

[A-Za-z0-9]+ any character inside brackets , one or more times

$ end of line

This regex accepts only numbers and alphabetic characters and at least 1 character

nissim abehcera
  • 821
  • 6
  • 7
  • 1
    OP didn't say it must *start* with an alpha character. This fails on input that starts with a digit. Try it on 9abcDEF – Richard II Feb 27 '19 at 21:59