how to validate a URL / website name in EditText in Android?

前端 未结 6 1665
深忆病人
深忆病人 2020-12-02 06:33

I want to take input, a URL or just a website name like, www.google.com from EditText in Android and on user click on the Button to submit

6条回答
  •  抹茶落季
    2020-12-02 06:59

    /** 
    * This is used to check the given URL is valid or not.
    * @param url
    * @return true if url is valid, false otherwise.
    */
    private boolean isValidUrl(String url) {
        Pattern p = Patterns.WEB_URL;
        Matcher m = p.matcher(url.toLowerCase());
        return m.matches();
    }
    

提交回复
热议问题