Hello everyone, I am going to share the code sample for filter the array using
Table of Contents
I. HTML 5 for input textbox
II. jQuery code for filter mobile number on textbox keyup.
HTML 5 Code Sample
jQuery Code Sample
$.grep()
method in jQuery Table of Contents
I. HTML 5 for input textbox
II. jQuery code for filter mobile number on textbox keyup.
HTML 5 Code Sample
<input id="mobileNumber" required pattern="\d{10}" validationmessage="Invalid
mobile number; must be ten digits">
<script type="text/javascript">
var userPhoneList = [];
$(function () {
filterPhoneNumbers();
});
function filterPhoneNumbers() {
$.getJSON("../API/Connect/GetUserPhones/@userSession.UserID")
.done(function (data) {
if (data !== undefined && data !== null) {
if (data.length > 0) {
$.each(data, function (key, val) {
userPhoneList.push(parseInt(val.MobileNo));
});
}
}
});
}
$('#mobileNumber').keyup(function () {
var mobile = $(this).val();
var result = $.grep(subscriberPhones, function (mPho, index) {
return mPho === parseInt(mobile);
});
if (result.length > 0) {
alert('Mobile number already exist.');
}
});
</script>