I am struggling to validate the three inputs mentioned above and having trouble using the right functions. Can someone please assist me with this?
Here is the HTML code for the 3 inputs:
<input id="name" ng-model="user.name" ng-blur="checkIfNameIsValid()" placeholder="Name"></input>
<input id="mobile" ng-model="user.phone" ng-blur="checfIfMobileNumIsValid()" placeholder="Mobile Number" maxlength="10"></input>
<input id="Aerror" ng-model="user.aadhar" ng-blur="checkIfAadharIsValid()" placeholder="Aadhar Number" maxlength="12"></input>
The JavaScript code:
$scope.checfIfMobileNumIsValid = function()
{
var mobile=/^\d{10}$/;
if($scope.user.phone.match(mobile) || $scope.user.phone == '' || $scope.user.phone == 'null' || $scope.user.phone == null)
{
$scope.user.mobErrorMsg = 'Mobile number is not valid';
$scope.error = true;
}
else
{
$scope.user.mobErrorMsg = '';
$scope.error = false;
}
}
$scope.checkIfNameIsValid = function()
{
var name='/^[a-zA-Z ]+$/';
if($scope.user.name.match(name)||$scope.user.name == ''||$scope.user.name=='null'||$scope.user.name==null)
{
$scope.user.NameErrorMsg = 'Name is not valid';
$scope.error = true;
}
else
{
$scope.user.NameErrorMsg = '';
$scope.error = false;
}
}
$scope.checkIfAadharIsValid = function()
{
var aadhar='/^\d{12}$/';
if($scope.user.aadhar.match(aadhar) || $scope.user.aadhar == '' || $scope.user.aadhar == 'null' || $scope.user.aadhar == null)
{
$scope.user.aadharErrorMsg = 'Aadhar is not valid';
$scope.error = true;
}
else
{
$scope.user.aadharErrorMsg = '';
$scope.error = false;
}
}
I am encountering an error in the browser console that says "cannot read property 'match' of undefined." Can someone provide guidance on how to resolve this issue?