Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allowing alphanumeric and dot in scope

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")
}

}
like image 261
babtech Avatar asked Dec 26 '22 20:12

babtech


1 Answers

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\.]*/"/>
like image 110
Chandermani Avatar answered Dec 28 '22 11:12

Chandermani