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


Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
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