Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8743887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:45:21+00:00 2026-06-13T11:45:21+00:00

I have encountered a strange behavior on android browser / webview. I was testing

  • 0

I have encountered a strange behavior on android browser / webview. I was testing an input that will automatically format to phone number format “(xxx) xxx-xxxx”. But then what happened was when I tapped or press any number on androids keyboard, the first input was like this “(x” but then the cursor was in between “(” and “x”. Is there a way to put the cursor after “x” value?

I tested this on iPhone and windows web browsers and it works fine. Please let me know if there are mistakes on my jquery or javascripts.

Thanks

HTML CODE:

<html>
    <head> 
        <title>Sample Phone Number Format</title>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
    </head>
    <body>
        <input type="text" id="phone" /> 

        <script type="text/javascript">
            $('#phone').on('keydown', function (event) {

                objval = $(this).val();
                if (event.keyCode == 46 || event.keyCode == 8) {} else {
                    if (!((event.keyCode > 47 && event.keyCode < 58) || (event.keyCode > 95 && event.keyCode < 106) || (objval.length > 13))) {
                        event.preventDefault();
                    } else {
                        if (objval.length == 0) {
                            $(this).val(objval + '(');
                            alert(objval + '(');
                        } else if (objval.length == 4) {
                            $(this).val(objval + ') ');
                            alert(objval + ') ');
                        } else if (objval.length == 9) {
                            $(this).val(objval + '-');
                            alert(objval + '-');
                        } else if (objval.length >= 14) {
                            if (event.keyCode == 9) {
                                return;
                            } else {
                                event.preventDefault();
                            }
                        }
                    }
                }
            });

            $('#phone').on('keydown', function (event) {

                var objVal = $(this).val();
                if(objVal.length < 14)
                {
                    validateCallerForm(objVal + String.fromCharCode((96 <= event.keyCode && event.keyCode <= 105)? event.keyCode-48 : event.keyCode));
                }
            });

            //Validates proper phone format, true if valid phone number, false otherwise
            function isValidPhoneNumber(elementValue) {
                var numberPattern = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;
                return numberPattern.test(elementValue);
            }

            //validates entire caller form, also updates css classes for proper response
            function validateCallerForm(PhoneNumber) {

                if (isValidPhoneNumber(PhoneNumber)) {
                    alert("true");
                } else {
                    alert("false");
                }

            }
        </script>
    </body>
</html>

Giving +50 Bounty to who’m will answer this correctly

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:45:22+00:00Added an answer on June 13, 2026 at 11:45 am

    I rewrite the code on my #phone keydown event and this will work on iPhone, Android, webkit browsers.

    $('#phone').on('keydown', function (event) {
        if (event.keyCode == 8 || event.keyCode == 37 || event.keyCode == 39) {
            // ignore if BKSPCE, left arrow, or right arrow
        } else {
            // validate if anything else
            inputval = $(this).val();
            var string = inputval.replace(/[^0-9]/g, "");
            var first3 = string.substring(0,3);
            var next3 = string.substring(3,6);
            var next4 = string.substring(6,10);
            var string = ("(" + first3 + ") " + next3 + "-" + next4);
            $(this).val(string);
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have encountered the strange problem, that linux c++ compiler includes the files from
I've encountered a strange behavior in __declspec(dllexport) in my project. I have a C++
I have not programmed C++ for a while and encountered a strange behavior when
I have encountered a strange behavior with a simple C++ class. classA.h class A
I've encountered the strange :colorscheme command behavior. I have some unusual symbols generated by
I have encountered strange behavoir while testing my application. I have a request to
I'm having a strange issue that I've never encountered before. I have a partial
I have encountered a strange linker problem that has me utterly perplexed : I
I have encountered some strange Perl behavior: using a Posix character class in a
Here is the pattern: $urlpattern = '%[^http://][^https://][\w]+(-[\w]+)*(\.[\w]+(-[\w]+)*)*\.[\w]{1,6}(\.[\w]{1,6})*[^/]%'; I have encountered a strange bug that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.