Reputation: 850
Following JavaScript & regex : How do I check if the string is ASCII only? how do I use the ASCII-only regex (/^[\x00-\x7F]*$/) in pattern attribute in HTML? I wish to restrict the user input to only ASCII characters.
<form class="row" name="marketDetails">
<input type="text" class="form-control col-md-12 form-sm" name="name" id="name" placeholder="Name"
value=""
maxlength="50"
pattern="[\x00-\x7F]"
ng-model="vm.marketMetaData.market_name" required/>
</form
Using pattern="[\x00-\x7F]" still lets me use non-ASCII character (e.g ¶) without any error in the form
Thanks.
Upvotes: 2
Views: 2622
Reputation: 850
Use pattern="[\x00-\x7F]+" - that did the trick. thanks! by Wiktor Stribiżew
Upvotes: 4