How can I allow only Alphanumeric characters and dots to a scope
<input type="text" ng-model="test" />
script
$scope.myFn = function(){
if($scope.test != ''){
alert("Please use only Alphanumeric characters or dots")
}
}
The better way is to define a ng-pattern
on the html input element. This would not allow incorrect value to be set on model. I have not tested the regular expression pattern.
<input type="text" ng-model="test" ng-pattern="/[a-zA-Z0-9\.]*/"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With