Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Validate Phone Number #607

Open
indumathymk opened this issue May 19, 2021 · 3 comments
Open

How to Validate Phone Number #607

indumathymk opened this issue May 19, 2021 · 3 comments

Comments

@indumathymk
Copy link

Is there is an option to validate given phone number is Mobile or Landline?

@sayertindall
Copy link

No, you need to use a service like Twilio verify or something similiar.

@reachbharathan
Copy link

This cannot be verified by this repo, maybe it need to be validated via paid service.

@r2ast
Copy link

r2ast commented Aug 26, 2021

You can build a cx function that take the number entered in the input field. Then the number is used an argument which goes to a function and check length and pattern of the number entered. If the patterns has mobile length, consider as mobile else consider it a landline. This is how i have made. I used a single to input to identlify that entered input is a email or phone.
Something like this.

validate_input1(email, phone) {
    var intRegex = /[0-9 -()+]+$/;

    if (intRegex.test(phone)) {
      // console.log("is phone", email);
      var obj1 = {
        mobile: phone,
      };

      if (phone.length < 9 || !intRegex.test(phone)) {
        alert("Please enter a valid phone number.");
        //return false;
      }
      return obj1;
    }
    if (email) {
      var eml = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
      // console.log("is email enterted", email);
      var obj2 = {
        email: email,
      };
      // console.log('get obj',obj);
      if (eml.test(email) == false) {
        alert("Please enter valid email address.");
      }

      return obj2;
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants