Devender Shekhawat
Devender Shekhawat

Reputation: 89

HTML pattern regex for no spaces

What will be the correct regex pattern for an HTML input which should allow only Letters, digits and @/./+/-/_. No spaces.

Upvotes: 4

Views: 18283

Answers (3)

Antony Mouse
Antony Mouse

Reputation: 31

Scratch that, there's actually a regex for that.

<input type="text" pattern="^\S+$">

That would work for MyName, but not for My Name.

Upvotes: 1

Cyril Beeckman
Cyril Beeckman

Reputation: 1278

You can use this regex for no space:

<form>
  <input type="text" pattern="[^' ']+" />
  <input type="submit" value="test submit">
</form>

So you can modify it to add your other rules

Upvotes: 12

Uladzimir Palekh
Uladzimir Palekh

Reputation: 1871

If characters order and count does not matter you can use this:

^[-a-zA-Z0-9@\.+_]+$

Upvotes: 1

Related Questions