Reputation: 89
What will be the correct regex pattern for an HTML input which should allow only Letters, digits and @/./+/-/_. No spaces.
Upvotes: 4
Views: 18283
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
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
Reputation: 1871
If characters order and count does not matter you can use this:
^[-a-zA-Z0-9@\.+_]+$
Upvotes: 1