Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using jquery validation for integers and other checking like mobile, pin code etc.
Its working absolutely fine in web browser. But when I am testing it in android browser or android chrome its just not working.



I searched in Google but did't found any suitable solutions.

What I have tried:

I used this bellow code:
JavaScript
function validate(evt) {
        var theEvent = evt || window.event;
        var key = theEvent.keyCode || theEvent.which;
        key = String.fromCharCode(key);
        var regex = /[0-9]/;
        if (!regex.test(key)) {
            theEvent.returnValue = false;
            if (theEvent.preventDefault) theEvent.preventDefault();
        }
    }


HTML
<input type="text" class="txtForexAmt" placeholder="0" value="@Model.TotalNoOfUnit" maxlength="10" />
Posted
Updated 16-Aug-16 21:33pm

1 solution

Its a known issue. Did you try any other browser of your device? It is the android WebView for lollipop which behaves like that. Uninstalling the webview could also fix the thing.
 
Share this answer
 
Comments
Arkadeep De 17-Aug-16 3:47am    
I tried native browser, mozila and chrome in my device and also in others. Uninstalled the webview too. Problem is still facing. Isn't there any solutions Ridoy?
ridoy 17-Aug-16 13:45pm    
Is JavaScript enabled in your webview...?
ridoy 17-Aug-16 13:45pm    
If not, use it and then test: WebView.getSettings().setJavaScriptEnabled(true);
Arkadeep De 3-Sep-16 12:36pm    
JavaScript is enabled. Problem was somewhere else. I was using onKeyPress...instead of that when I am using onKeyDown or OnKeyUp methods its working fine. But I didn't found why OnKeyPress was not working in mobile browser. Anyway thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900