JavaScript Tutorial/Dojo toolkit/Validation
Содержание
Check number format
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojox.validate.web");
dojo.require("dojox.validate._base");
dojo.require("dojox.validate.creditCard");
dojo.require("dojox.validate.isbn");
function testIt() {
var s = dojox.validate.isNumberFormat("555-12-3456",{ format : "###-##-####" });
alert(s)
}
</script>
</head>
<body onLoad="testIt();">
</body>
</html>
Check phone number format
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojox.validate.web");
dojo.require("dojox.validate._base");
dojo.require("dojox.validate.creditCard");
dojo.require("dojox.validate.isbn");
function testIt() {
var s = dojox.validate.isNumberFormat("(555)/123-3456",{ format : "(###)/###-####" });
alert(s)
}
</script>
</head>
<body onLoad="testIt();">
</body>
</html>
Validate credit card number
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojox.validate.web");
dojo.require("dojox.validate._base");
dojo.require("dojox.validate.creditCard");
dojo.require("dojox.validate.isbn");
function testIt() {
var s = dojox.validate.isValidCreditCardNumber("1111-1111-1111-1111");
alert(s)
}
</script>
</head>
<body onLoad="testIt();">
</body>
</html>
Validate email
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojox.validate.web");
dojo.require("dojox.validate._base");
dojo.require("dojox.validate.creditCard");
dojo.require("dojox.validate.isbn");
function testIt() {
var s = dojox.validate.isEmailAddress("joe@nasa.gov");
alert(s)
}
</script>
</head>
<body onLoad="testIt();">
</body>
</html>
Validate email address
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojox.validate.web");
dojo.require("dojox.validate._base");
dojo.require("dojox.validate.creditCard");
dojo.require("dojox.validate.isbn");
function testIt() {
var s = dojox.validate.isIpAddress("127.0.0.1");
alert(s)
}
</script>
</head>
<body onLoad="testIt();">
</body>
</html>
Validate Isbn
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojox.validate.web");
dojo.require("dojox.validate._base");
dojo.require("dojox.validate.creditCard");
dojo.require("dojox.validate.isbn");
function testIt() {
var s = dojox.validate.isValidIsbn("999-1-4444-1111-5");
alert(s)
}
</script>
</head>
<body onLoad="testIt();">
</body>
</html>
Validate Luhn number
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojox.validate.web");
dojo.require("dojox.validate._base");
dojo.require("dojox.validate.creditCard");
dojo.require("dojox.validate.isbn");
function testIt() {
var s = dojox.validate.isValidLuhn("1111 1111 1111 1111");
alert(s)
}
</script>
</head>
<body onLoad="testIt();">
</body>
</html>
Validate Max length of TextBox
<html>
<head>
<link rel="StyleSheet" type="text/css"
href="js/dojo/dijit/themes/tundra/tundra.css">
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojo.parser");
dojo.require("dijit.form.TextBox");
dojo.require("dijit.form.ValidationTextBox");
dojo.require("dijit.form.Button");
</script>
</head>
<body class="tundra">
<label>First Name:</label>
<input type="text"
maxlength=25
name="first"
dojoType="dijit.form.TextBox"
trim="true"
propercase="true"/><br>
</body>
</html>
Zipcode validation
<html>
<head>
<link rel="StyleSheet" type="text/css"
href="js/dojo/dijit/themes/tundra/tundra.css">
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojo.parser");
dojo.require("dijit.form.ValidationTextBox");
dojo.require("dijit.form.ruboBox");
dojo.require("dojo.data.ItemFileReadStore");
</script>
</head>
<body class="tundra">
<div class="formContainer">
<form method="get" name="custForm">
<div class="formTitle">Form</div>
<div class="formRow">
<label for="zipCode">Zip Code: </label>
<input type="text" id="zipCode" name="zipCode" size="10"
dojoType="dijit.form.ValidationTextBox"
trim="true"
required="true"
regExp="\d{5}|\d{5}-d{4}"
maxlength="10"
promptMessage="Enter zip code."
invalidMessage="Invalid zip code (NNNNN)."
/>
</div>
</form>
</div>
</body>
</html>