python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
filtering arrays with jQuery grep

Filtering Array using $.grep() method

Hello everyone, I am going to share the code sample for filter the array using $.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">

jQuery Code Sample

<script type="text/javascript">
    var userPhoneList = [];
    $(function () {

    function filterPhoneNumbers() {
            .done(function (data) {
                if (data !== undefined && data !== null) {
                    if (data.length > 0) {
                        $.each(data, function (key, val) {

    $('#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.');


Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - and
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like Powered by Blogger.
ASK Questions