当前位置:网站首页>JS mailbox regular expression
JS mailbox regular expression
2022-06-23 20:40:00 【It workers】
How to verify whether the mailbox expression is correct ?
Use Regular expressions Maybe the best way , You can see some examples here ( stay chrome Test on the console ).
function validateEmail(email) {
const re = /^(([^<>()\[\]\.,;:\[email protected]"]+(\.[^<>()\[\]\.,;:\[email protected]"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}The following is acceptable unicode Examples of regular expressions for :
const re = /^(([^<>()\[\]\.,;:\[email protected]\"]+(\.[^<>()\[\]\.,;:\[email protected]\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\[email protected]\"]+\.)+[^<>()[\]\.,;:\[email protected]\"]{2,})$/i;
But remember , We should not rely solely on JavaScript verification . You can easily disable JavaScript. It is also necessary to verify on the server side .
Here is an example :
function validateEmail(email) {
const re = /^(([^<>()[\]\.,;:\[email protected]\"]+(\.[^<>()[\]\.,;:\[email protected]\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
function validate() {
const $result = $("#result");
const email = $("#email").val();
$result.text("");
if (validateEmail(email)) {
$result.text(email + " is valid :)");
$result.css("color", "green");
} else {
$result.text(email + " is not valid :(");
$result.css("color", "red");
}
return false;
}
$("#validate").on("click", validate);<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form> <p>Enter an email address:</p> <input id='email'> <button type='submit' id='validate'>Validate!</button> </form> <h2 id='result'></h2>
边栏推荐
- How to log in to the server through the fortress machine to transfer files? What are the specific steps?
- Leaders of Hangcheng street, Bao'an District and their delegation visited lianchengfa for investigation
- @@Script implementation of ishell automatic deployment
- 小程序开发框架推荐
- 手续费佣金低的券商,华泰证券网上开户安全吗
- 教你如何用网页开发APP
- Making CSR file for face core
- Script tag attributes and & lt; noscript&gt; label
- 【Golang】快速复习指南QuickReview(一)——字符串string
- Goldfish rhca memoirs: do447 managing user and team access -- effectively managing users with teams
猜你喜欢

ZABBIX monitoring - Aruba AP operation data

Implementation of microblog system based on SSM

Kubernetes 资源拓扑感知调度优化

Open source SPL redefines OLAP server

Rstudio 1.4 software installation package and installation tutorial

Official announcement. Net 7 preview 5

5 月最大的 GameFi 崩溃受害者能否在熊市中生存?| May Monthly Report

Technology sharing | wvp+zlmediakit realizes streaming playback of camera gb28181

Yaokui tower in Fengjie, Chongqing, after its completion, will be the safety tower for Sichuan river shipping with five local scholars in the company

小程序开发框架推荐
随机推荐
How to dispose of the words on the picture? How do I add text to a picture?
Is Huishang futures trading software formal? How to download safely?
Strokeit- the joy of one handed fishing you can't imagine
Fortress deployment server setup operation guide for novices
OHOS LTS 3.0移植到RaspberryPi 4B
同花顺网上开户安全吗,佣金高不高
35岁危机?内卷成程序员代名词了…
Kinsoku jikou desu新浪股票接口变动
vs2022scanf函数的使用,使用scanf的报错-返回值被忽略:解决·方法
Interview with Mo Tianlun | ivorysql wangzhibin - ivorysql, an Oracle compatible open source database based on PostgreSQL
【Golang】怎样优雅的清空切片
How to process the text of a picture into a table? Can the text in the picture be transferred to the document?
How to log in to the server through the fortress machine to transfer files? What are the specific steps?
Digital procurement transformation solution: SaaS procurement management platform promotes enterprise sunshine procurement
How to make a commodity price tag
【Golang】快速复习指南QuickReview(三)——map
GL Studio 5 installation and experience
GL Studio 5 安装与体验
Are internal consultants and external consultants in SAP implementation projects difficult or successful?
Configure two databases in master-slave database mode (master and slave)