Home Web Front-end JS Tutorial JS common verification functions_javascript skills

JS common verification functions_javascript skills

May 16, 2016 pm 06:54 PM
js

//Check whether it is composed entirely of digits
function isDigit(s)
{
var patrn=/^[0-9]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}
//Verify login name: only 5-20 characters starting with letters and numbers can be entered. Strings of "_" and "."
function isRegisterUserName(s)
{
var patrn=/^[a-zA-Z]{1}([a-zA-Z0 -9]|[._]){4,19}$/;
if (!patrn.exec(s)) return false
return true
}
//proof Verify user name: You can only enter 1-30 strings starting with letters
function isTrueName(s)
{
var patrn=/^[a-zA-Z]{1, 30}$/;
if (!patrn.exec(s)) return false
return true
}
//Verify password: only 6-20 letters can be entered, Numbers, underscores
function isPasswd(s)
{
var patrn=/^(w){6,20}$/;
if (!patrn.exec(s)) return false
return true
}
//Verify ordinary telephone and fax numbers: it can start with " ", and in addition to numbers, it can contain "-"
function isTel( s)
{
//var patrn=/^[ ]{0,1}(d){1,3}[ ]?([-]?(d){1,12}) $/ ;
var patrn=/^[ ]{0,1}(d){1,3}[ ]?([-]?((d)|[ ]){1,12}) $/;
if (!patrn.exec(s)) return false
return true
}
//Verification mobile phone number: must start with a number, in addition to numbers, it can contain "-"
function isMobil(s)
{
var patrn=/^[ ]{0,1}(d){1,3}[ ]?([-]?((d) |[ ]){1,12}) $/;
if (!patrn.exec(s)) return false
return true
}
//Verify postal code
function isPostalCode(s)
{
//var patrn=/^[a-zA-Z0-9]{3,12}$/;
var patrn=/^[a-zA-Z0- 9 ]{3,12}$/;
if (!patrn.exec(s)) return false
return true
}
//Verify search keywords
function isSearch( s)
{
var patrn=/^[^`~!@#$%^&*() =|\][]{}:;',./?]{1} [^`~!@$%^&() =|\][]{}:;',.?]{0,19}$/;
if (!patrn.exec(s) ) return false
return true
}
function isIP(s) //by zergling
{
var patrn=/^[0-9.]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}
/*********************************************************************************
* FUNCTION: isBetween
* PARAMETERS: val AS any value
* lo AS Lower limit to check
* hi AS Higher limit to check
* CALLS: NOTHING
* RETURNS: TRUE if val is between lo and hi both inclusive, otherwise false.
***************
******************************************************************/
function isBetween (val, lo, hi) {
if ((val hi)) { return(false); }
else { return(true); }
}
/*********************************************************************************
* FUNCTION: isDate checks a valid date
* PARAMETERS: theStr AS String
* CALLS: isBetween, isInt
* RETURNS: TRUE if theStr is a valid date otherwise false.
**********************************************************************************/
function isDate ( theStr) {
var the1st = theStr.indexOf('-');
var the2nd = theStr.lastIndexOf('-');
if (the1st == the2nd) { return(false); }
else {
var y = theStr.substring(0,the1st);
var m = theStr.substring(the1st 1,the2nd);
var d = theStr.substring(the2nd 1,theStr .length);
var maxDays = 31;
if (isInt(m)==false || isInt(d)==false || isInt(y)==false) {
return(false ); }
else if (y.length else if (!isBetween (m, 1, 12)) { return(false); }
else if (m==4 || m==6 || m==9 || m==11) maxDays = 30;
else if (m==2) {
if (y % 4 > 0 ) maxDays = 28;
else if (y % 100 == 0 && y % 400 > 0) maxDays = 28;
else maxDays = 29;
}
if (isBetween(d, 1 , maxDays) == false) { return(false); }
else { return(true); }
}
}
/*********************************************************************************
* FUNCTION: isEuDate checks a valid date in British format
* PARAMETERS: theStr AS String
* CALLS: isBetween, isInt
* RETURNS: TRUE if theStr is a valid date otherwise false.
**********************************************************************************/
function isEuDate ( theStr) {
if (isBetween(theStr.length, 8, 10) == false) { return(false); }
else {
var the1st = theStr.indexOf('/');
var the2nd = theStr.lastIndexOf('/');
if (the1st == the2nd) { return(false); }
else {
var m = theStr.substring(the1st 1,the2nd );
var d = theStr.substring(0,the1st);
var y = theStr.substring(the2nd 1,theStr.length);
var maxDays = 31;
if (isInt( m)==false || isInt(d)==false || isInt(y)==false) {
return(false); }
else if (y.length else if (isBetween (m, 1, 12) == false) { return(false); }
else if (m==4 || m==6 || m==9 || m==11) maxDays = 30;
else if (m==2) {
if (y % 4 > 0) maxDays = 28;
else if (y % 100 == 0 && y % 400 > 0) maxDays = 28;
else maxDays = 29;
}
if (isBetween(d, 1, maxDays) == false) { return(false); }
else { return(true); }
}
}
}
/**************************************************** ****************************
* 기능: 날짜 비교! 어느 것이 최신입니까!
* 매개변수: lessDate,moreDate AS String
* 호출: isDate,isBetween
* 반환: lessDate****************인 경우 TRUE ************************************************** ***************/
function isComdate (lessDate , moreDate)
{
if (!isDate(lessDate)) { return(false);}
if (!isDate (moreDate)) { return(false);}
var less1st = lessDate.indexOf('-');
var less2nd = lessDate.lastIndexOf('-');
var more1st = moreDate.indexOf('-');
var more2nd = moreDate.lastIndexOf('-');
var lessy = lessDate.substrin(0,less1st);
var lessm = lessDate.substring(less1st 1,less2nd);
var lessd = lessDate.substring(less2nd 1,lessDate.length);
var morey = moreDate.substring(0,more1st);
var morem = moreDate.substring(more1st 1,more2nd);
var mored = moreDate.substring(more2nd 1,moreDate.length);
var Date1 = new Date(lessy,lessm,lessd);
var Date2 = new Date(morey,morem,mored);
if (Date1>Date2) { return(false);}
return(true);
}
/**************************************************** *****************************
* FUNCTION isEmpty는 매개변수가 비어 있는지 또는 null인지 확인합니다.
* PARAMETER str AS 문자열
********************************************** ************************************/
function isEmpty (str) {
if ((str==null)||(str.length==0)) return true;
그렇지 않으면 return(false);
}
/**************************************************** *****************************
* 함수: isInt
* 매개변수: theStr AS String
* RETURNS : 전달된 매개변수가 정수이면 TRUE, 그렇지 않으면 FALSE
* CALLS: isDigit
**************************** ************************************************** ****/
function isInt (theStr) {
var flag = true;
if (isEmpty(theStr)) { 플래그=false; }
else
{ for (var i=0; iif (isDigit(theStr.substring(i,i 1)) == false) {
플래그 = 거짓; 부서지다;
}
}
}
return(플래그);
}
/**************************************************** *****************************
* 기능: isReal
* 매개변수: heStr AS String
decLen AS 정수(마침표 뒤의 자릿수)
* 반환: theStr이 부동 소수점이면 TRUE, 그렇지 않으면 FALSE
* 호출: isInt
******************** ************************************************** ***************/
function isReal (theStr, decLen) {
var dot1st = theStr.indexOf('.');
var dot2nd = theStr.lastIndexOf('.');
var K = 참;
if (isEmpty(theStr))는 false를 반환합니다.
if (dot1st == -1) {
if (!isInt(theStr)) return(false);
그렇지 않으면 반환(true);
}
else if (dot1st != dot2nd) return (false);
else if (dot1st==0) return (false);
else {
var intPart = theStr.substring(0, dot1st);
var decPart = theStr.substring(dot2nd 1);
if (decPart.length > decLen) return(false);
else if (!isInt(intPart) || !isInt(decPart)) return (false);
else if (isEmpty(decPart)) return (false);
그렇지 않으면 반환(true);
}
}
/**************************************************** *****************************
* 기능: isEmail
* 매개변수: 문자열(이메일 주소)
* 반환: 문자열이 유효한 이메일 주소인 경우 TRUE
* 전달된 문자열이 유효한 이메일 주소가 아닌 경우 FALSE
* 이메일 형식: AnyName@EmailServer 예: webmaster@hotmail.com
* @ 기호는 이메일 주소에 한 번만 나타날 수 있습니다.
************************************************************************ **********************************/
function isEmail (theStr) {
var atIndex = theStr.indexOf('@');
var dotIndex = theStr.indexOf('.', atIndex);
var 플래그 = true;
theSub = theStr.substring(0, dotIndex 1)
if ((atIndex { return(false); }
else { return(true); }
}
/**************************************************** *****************************
* 기능: newWindow
* 매개변수: doc -> 열 문서 새 창
hite -> 새 창 높이
wide -> 새 창 너비
bars -> 1-스크롤 막대 = YES 0-스크롤 막대 = NO
크기 조정 -> 1- 크기 조정 가능 = 예 0-크기 조정 가능 = 아니요
* 호출: 없음
* 반환: 새 창 인스턴스
************************ ************************************************** *********/
function newWindow(doc, hite, wide, bar, resize) {
var winNew="_blank";
var pt="toolbar=0,location=0,directories=0,status=0,menubar=0,";
opt =("scrollbars=" 바 ",");
opt =("resizing=" 크기 조정 ",");
opt =("너비="와이드 ",");
opt =("height=" 하이트);
winHandle=window.open(doc,winNew,opt);
반환;
}
/*********************************************************************************
* FUNCTION: DecimalFormat
* PARAMETERS: paramValue -> Field value
* CALLS: NONE
* RETURNS: Formated string
**********************************************************************************/
function DecimalFormat (paramValue) {
var intPart = parseInt(paramValue);
var decPart =parseFloat(paramValue) - intPart;
str = " ";
if ((decPart == 0) || (decPart == null)) str = (intPart ".00");
else str = (intPart decPart);
return (str) ;
}
"^\d $" //Non-negative integer (positive integer 0)
"^[0-9]*[1-9][0-9]*$" // Positive integer
"^((-\d )|(0 ))$" //Non-positive integer (negative integer 0)
"^-[0-9]*[1-9][0- 9]*$" //Negative integer
"^-?\d $" //Integer
"^\d (\.\d )?$" //Non-negative floating point number (positive floating point number 0 )
"^(([0-9] \.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9 ]*\.[0-9] )|([0-9]*[1-9][0-9]*))$" //Positive floating point number
"^((-\d (\ .\d )?)|(0 (\.0 )?))$" //Non-positive floating point number (negative floating point number 0)
"^(-(([0-9] \.[0- 9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9] )|([0-9]* [1-9][0-9]*)))$" // Negative floating point number
"^(-?\d )(\.\d )?$" //Floating point number
"^ [A-Za-z] $" //A string consisting of 26 English letters
"^[A-Z] $" //A string consisting of 26 uppercase English letters
"^[a-z ] $"  // A string consisting of 26 lowercase English letters
"^[A-Za-z0-9] $"  // A string consisting of numbers and 26 English letters
"^ \w $"  //A string consisting of numbers, 26 English letters or underscores
"^[\w-] (\.[\w-] )*@[\w-] (\.[\ w-] ) $"   //email address
"^[a-zA-z] ://(\w (-\w )*)(\.(\w (-\w )*))* (\?\S*)?$"  //url
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use JS and Baidu Maps to implement map pan function How to use JS and Baidu Maps to implement map pan function Nov 21, 2023 am 10:00 AM

How to use JS and Baidu Map to implement map pan function Baidu Map is a widely used map service platform, which is often used in web development to display geographical information, positioning and other functions. This article will introduce how to use JS and Baidu Map API to implement the map pan function, and provide specific code examples. 1. Preparation Before using Baidu Map API, you first need to apply for a developer account on Baidu Map Open Platform (http://lbsyun.baidu.com/) and create an application. Creation completed

Recommended: Excellent JS open source face detection and recognition project Recommended: Excellent JS open source face detection and recognition project Apr 03, 2024 am 11:55 AM

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages ​​and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

How to create a stock candlestick chart using PHP and JS How to create a stock candlestick chart using PHP and JS Dec 17, 2023 am 08:08 AM

How to use PHP and JS to create a stock candle chart. A stock candle chart is a common technical analysis graphic in the stock market. It helps investors understand stocks more intuitively by drawing data such as the opening price, closing price, highest price and lowest price of the stock. price fluctuations. This article will teach you how to create stock candle charts using PHP and JS, with specific code examples. 1. Preparation Before starting, we need to prepare the following environment: 1. A server running PHP 2. A browser that supports HTML5 and Canvas 3

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Dec 17, 2023 pm 06:55 PM

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

How to use JS and Baidu Map to implement map click event processing function How to use JS and Baidu Map to implement map click event processing function Nov 21, 2023 am 11:11 AM

Overview of how to use JS and Baidu Maps to implement map click event processing: In web development, it is often necessary to use map functions to display geographical location and geographical information. Click event processing on the map is a commonly used and important part of the map function. This article will introduce how to use JS and Baidu Map API to implement the click event processing function of the map, and give specific code examples. Steps: Import the API file of Baidu Map. First, import the file of Baidu Map API in the HTML file. This can be achieved through the following code:

How to use JS and Baidu Maps to implement map heat map function How to use JS and Baidu Maps to implement map heat map function Nov 21, 2023 am 09:33 AM

How to use JS and Baidu Maps to implement the map heat map function Introduction: With the rapid development of the Internet and mobile devices, maps have become a common application scenario. As a visual display method, heat maps can help us understand the distribution of data more intuitively. This article will introduce how to use JS and Baidu Map API to implement the map heat map function, and provide specific code examples. Preparation work: Before starting, you need to prepare the following items: a Baidu developer account, create an application, and obtain the corresponding AP

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts Dec 18, 2023 pm 03:39 PM

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese

The relationship between js and vue The relationship between js and vue Mar 11, 2024 pm 05:21 PM

The relationship between js and vue: 1. JS as the cornerstone of Web development; 2. The rise of Vue.js as a front-end framework; 3. The complementary relationship between JS and Vue; 4. The practical application of JS and Vue.

See all articles