首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >印度手机号、电子邮件Id和密码的正则表达式: React Js || Next Js

印度手机号、电子邮件Id和密码的正则表达式: React Js || Next Js
EN

Stack Overflow用户
提问于 2021-06-24 23:07:32
回答 1查看 39关注 0票数 0

这是印度本地手机号码验证和印度国际手机号码验证的正则表达式。

从9,8,7开始,你还可以添加更多。

电子邮件和密码

Hear是代码

请立即订阅制作视频My Youtube Channel

代码语言:javascript
复制
    const status = validate();
    if (status === true) {
      alert('Login');
    }
  };

  const doSignUp = () => {
    const status = validate();
    if (status === true) {
      alert('Sign Up');
    }
  };

  const validate = () => {
    if (
      /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(
        email
      ) &&
      email.includes('.')
    ) {
      if (
        /^(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{6,99}$/.test(password)
      ) {
        if (
          /^(?:(?:\+|0{0,2})91(\s*[\-]\s*)?|[0]?)?[6789]\d{9}$/.test(
            phoneNumber
          )
        ) {
          return true;
        } else {
          alert('Invalid Phone Number');
          return false;
        }
      } else {
        alert(
          'Invalid, Password should contane Capital Letter, Small Letter , Number and Symbol'
        );
        return false;
      }
    } else {
      alert('You have entered an invalid email address!');
      return false;
    }
  };```
EN

回答 1

Stack Overflow用户

发布于 2021-06-24 23:07:32

代码语言:javascript
复制
    const status = validate();
    if (status === true) {
      alert('Login');
    }
  };

  const doSignUp = () => {
    const status = validate();
    if (status === true) {
      alert('Sign Up');
    }
  };

  const validate = () => {
    if (
      /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(
        email
      ) &&
      email.includes('.')
    ) {
      if (
        /^(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{6,99}$/.test(password)
      ) {
        if (
          /^(?:(?:\+|0{0,2})91(\s*[\-]\s*)?|[0]?)?[6789]\d{9}$/.test(
            phoneNumber
          )
        ) {
          return true;
        } else {
          alert('Invalid Phone Number');
          return false;
        }
      } else {
        alert(
          'Invalid, Password should contane Capital Letter, Small Letter , Number and Symbol'
        );
        return false;
      }
    } else {
      alert('You have entered an invalid email address!');
      return false;
    }
  };```
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68118324

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档