I am looking for a
<input type="text" name="serialNumber" data-ng-model="SerialNumber" ng-pattern="/^[a-zA-Z0-9_-]*$/" maxlength="100"/>
<div data-ng-if="Form.serialNumber.$error.pattern" class="error">Please enter valid serial number</div>
If you want to allow a space in your input, you need to include it into the character class.
According to docs:
If set to
falseAngular will not automatically trim the input. This parameter is ignored for
input[type=password]controls, which will never trim the input.
So, if your input field is not password field I'd recommend:
\w stands for
[A-Za-z0-9_] in JS, the underscore does not have to be escaped and the hyphen at the end of the character class does not need escaping either.