{"id":16756109,"url":"https://github.com/mihaelisaev/maskededittextwatcher","last_synced_at":"2025-08-12T16:40:32.889Z","repository":{"id":144805206,"uuid":"84158647","full_name":"MihaelIsaev/MaskedEditTextWatcher","owner":"MihaelIsaev","description":"Custom TextWatcher for EditText to mask phone number on-the-fly even with automatic country mask detection","archived":false,"fork":false,"pushed_at":"2017-03-07T22:29:58.000Z","size":228,"stargazers_count":11,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-06T05:48:55.331Z","etag":null,"topics":["android-library"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MihaelIsaev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-03-07T05:29:26.000Z","updated_at":"2024-10-23T04:42:07.000Z","dependencies_parsed_at":"2023-09-25T23:07:52.582Z","dependency_job_id":"bcdc8fb6-7064-476f-90cb-567716e138df","html_url":"https://github.com/MihaelIsaev/MaskedEditTextWatcher","commit_stats":{"total_commits":3,"total_committers":2,"mean_commits":1.5,"dds":"0.33333333333333337","last_synced_commit":"86c9e9761f9d84e9bd3c5511e14d1f6e5e550097"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/MihaelIsaev/MaskedEditTextWatcher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MihaelIsaev%2FMaskedEditTextWatcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MihaelIsaev%2FMaskedEditTextWatcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MihaelIsaev%2FMaskedEditTextWatcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MihaelIsaev%2FMaskedEditTextWatcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MihaelIsaev","download_url":"https://codeload.github.com/MihaelIsaev/MaskedEditTextWatcher/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MihaelIsaev%2FMaskedEditTextWatcher/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270099337,"owners_count":24527028,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android-library"],"created_at":"2024-10-13T03:24:50.559Z","updated_at":"2025-08-12T16:40:32.861Z","avatar_url":"https://github.com/MihaelIsaev.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MaskedEditTextWatcher\nCustom TextWatcher for EditText to mask phone number on-the-fly even with automatic country mask detection\n\n![Demonstration GIF](https://github.com/MihaelIsaev/MaskedEditTextWatcher/raw/master/stuff/example.gif)\n\n## How to install\nvia Gradle\n```\ncompile 'com.mihaelisaev:masked-edit-text-watcher:1.0.0'\n```\n\n## How to use\n\n### Manual list of masks\n```java\n//Instantiate your EditText\nEditText phoneTextField = (EditText) findViewById(R.id.phoneTextField);\n//Create text watcher\nMaskedEditTextWatcher simpleListener = new MaskedEditTextWatcher(phoneTextField, new MaskedEditTextWatcherDelegate() {\n    @Override\n    public String maskForCountryCode(String text) {\n        //Here you receive just entered text\n        //and you should return the mask or null\n        if (text.equals(\"1\")) {\n            return \"+1 ###-###-####\";\n        } else if (text.equals(\"7\")) {\n            return \"+7 (###) ###-##-##\";\n        } else if (text.equals(\"44\")) {\n            return \"+44 (##) ###-####\";\n        } else if (text.equals(\"64\")) {\n            return \"+64 ## # (###) ##-##\";\n        }\n        return null;\n    }\n});\n//Add the textWatcher to your text field\nphoneTextField.addTextChangedListener(simpleListener);\n```\n\n### Get mask from google phone library\n\nFirst of all add the following line to your app module gradle file to install the google phone library\n```\ncompile 'com.googlecode.libphonenumber:libphonenumber:7.1.1'\n```\n\nThen just implement MaskedEditTextWatcherDelegate using google phone library\n```java\n//Instantiate your EditText\nEditText phoneTextField = (EditText) findViewById(R.id.phoneTextField);\n//Create text watcher\nMaskedEditTextWatcher glibListener = new MaskedEditTextWatcher(phoneTextField, new MaskedEditTextWatcherDelegate() {\n    @Override\n    public String maskForCountryCode(String text) {\n        //Here you receive just entered text\n        //and you should return the mask or null\n        PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();\n        try {\n            //We just should check if entered text is numeric\n            Double.parseDouble(text);\n            //Then we should get the region code based on first entered digits\n            String regionCode = phoneUtil.getRegionCodeForCountryCode(Integer.parseInt(text));\n            //Then we get an example number for this region\n            Phonenumber.PhoneNumber exampleNumber = phoneUtil.getExampleNumber(regionCode);\n            //We should check the number and if it's null then we alse return null\n            if (exampleNumber == null) return null;\n            //Here we get country code as digits\n            int countryCodeForRegion = phoneUtil.getCountryCodeForRegion(regionCode);\n            //Here we create the string with country code with + symbol\n            String detectedCountryCode = \"+\" + countryCodeForRegion;\n            //Here we create example number but wothout country code\n            String example = phoneUtil.format(exampleNumber, PhoneNumberUtil.PhoneNumberFormat.NATIONAL);\n            example = example.replace(\"8 \", \"\"); //needed for Russian example number\n            example = example.replace(detectedCountryCode, \"\");\n            //And finally we create full mask with country code\n            return detectedCountryCode+\" \"+example.replaceAll(\"\\\\d\", \"#\");\n        } catch (NumberFormatException e) {\n            //If entered text is not numeric then we shoul return null\n            return null;\n        }\n    }\n});\n//Add the textWatcher to your text field\nphoneTextField.addTextChangedListener(glibListener);\n```\n\n*This lib is under Apache 2.0 license.*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmihaelisaev%2Fmaskededittextwatcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmihaelisaev%2Fmaskededittextwatcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmihaelisaev%2Fmaskededittextwatcher/lists"}