Search code examples
regexxenforo

REGEX That Doesn't Allow Spaces or Special Characters


Salutations, I need a regular expression in which doesn't allow spaces or special characters. All replies are appreciated. Thank you.

For example, if somebody enters $cdIAb!%, a bcd, or $ab%c d@, it would be rejected. If they entered cdIAb it would be accepted.

This is for an Xenforo forum.


Solution

  • The regex express you would use is ^(\d|\w)+$:

    <form>
      <input type="text" pattern="^(\d|\w)+$">
      <button type="submit">submit</button>
    </form>
    

    Regex101 example.