2

I have User registration page in Phonegap www folder.I want to validate email id and phone number using native android functions.How do I do that?

Shweta
  • 31
  • 2
  • Please refer this link - http://stackoverflow.com/questions/6358380/phone-number-validation-android & http://stackoverflow.com/questions/5958665/validation-for-a-cell-number-in-android- for phone number detection. – AkashG Nov 27 '12 at 06:01
  • And this link for mail validation- http://stackoverflow.com/questions/9355899/android-email-edittext-validation & this blog will also help you - http://chandan-tech.blogspot.in/2010/11/validating-email-address-pattern-in.html , http://www.technotalkative.com/android-validate-email-address/ – AkashG Nov 27 '12 at 06:03

1 Answers1

0

We have to write JS interface to execute java code from javascript.
Write following code in your onCreate method:

public class MainActivity extends DroidGap {
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.loadUrl("file:///android_asset/www/index.html");

        WebView webView = (WebView) findViewById(R.id.webView);
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webView.addJavascriptInterface(new Object()
             {
                public void performClick(String emailAdress, String phoneNo)
                {
                   // Validate email address and Phone number here
                }
             },"MyAndroid");
}
}

To call JS interface in phonegap app, write javascript function:

&ltscript>
document.getElementById("validateButton").addEventListener('touchstart',touchPagePressed);// you can use 'onclick' also
function touchPagePressed()
{
   // MyAndroid interface will execute java's performClick method
   MyAndroid.performClick($("#emailId").val(),$("#phoneNo").val());
}
&lt/script>
Mayur Birari
  • 5,837
  • 8
  • 34
  • 61