0

So I have a regex expression to validate phone numbers from Argentina, these numbers are actually in this type

0351 15589834

in which this regex let me write that number without the 0 and 15 which is used to short de number

 private fun isValidPhoneNumber(phoneNumber: String):Boolean {
        val regex = "/^(?:(?:00)?549?)?0?(?:11|[2368]\\d)(?:(?=\\d{0,2}15)\\d{2})??\\d{8}\$/"
        val pattern = Pattern.compile(regex)
        val matcher = pattern.matcher(phoneNumber)
        return matcher.matches()
    }

    private fun attachEditTextPhoneListener(){
        etxt_verificar_num.addTextChangedListener(object: TextWatcher {
            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                if(isValidPhoneNumber(s.toString())){
                    enableContinueBtn()
                }else{
                    disableContinueBtn()
                }
            }
            override fun afterTextChanged(s: Editable?) {}
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
        })
    }

Now, when I start typing my numbers it does never validate them, but I have checked the regex

/^(?:(?:00)?549?)?0?(?:11|[2368]\\d)(?:(?=\\d{0,2}15)\\d{2})??\\d{8}\$/

here https://regex101.com/ with the number I have provided and it works , why its not matching in my code?

SNM
  • 5,625
  • 9
  • 28
  • 77

0 Answers0