js判断时间
作者:佚名 文章来源:网络 更新时间
:2007-5-30 9:19:03
function verifyDate(textObj){
var tmpDateValue = textObj.value;
var tmpLength = tmpDateValue.length;
if (tmpLength == 0){
return true;
}
for (var i = 0; i < tmpLength;i++){
aChar = tmpDateValue.substring(i,i+1);
if(aChar != "-" && (aChar < "0" ¦¦ aChar > "9")) {
alert ("请按照格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
}
if ((tmpLength < 8 ¦¦ tmpLength > 10) && tmpLength != 0) {
alert ("请按照格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
for (var j= 0; j < 4;j++){
aChar = tmpDateValue.substring(j,j+1);
if(aChar < "0" ¦¦ aChar > "9") {
alert ("请按照格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
}
if (tmpDateValue.substring(4,5) != "-" ¦¦ tmpDateValue.substring(5,6) == "-"){
alert ("请按规定格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
if (tmpLength == 8){
if (tmpDateValue.substring(6,7) != "-" ¦¦ tmpDateValue.substring(7,8) == "-" ){
alert ("请按规定格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
}
if (tmpLength == 9){
if (tmpDateValue.substring(8,9) == "-" ){
alert ("请按规定格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
}
if (tmpLength == 10){
if (tmpDateValue.substring(7,8) != "-" ¦¦ tmpDateValue.substring(6,7) == "-" ¦¦ tmpDateValue.substring(8,9) == "-" ¦¦ tmpDateValue.substring(9,10) == "-" ){
alert ("请按规定格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
}
var count=0;
for (var k = 0; k < tmpLength;k++){
aChar = tmpDateValue.substring(k,k+1);
if(aChar == "-") {
count++;
}
}
if (count!=2){
alert("请按照格式输入日期!(yyyy-mm-dd)");
textObj.focus(this);
textObj.select(this);
return false;
}
return true;
}
上面的是校验输入框内是否是日期,且格式是由数字和"-"符号构成;符合"yyyy-m-d"或"yyyy-m-dd"或"yyyy-mm-d"或"yyyy-mm-dd"的格式(即textObj.value.length为8、9、10中的一种)
function isFloat(textObj){
var tmpFloatValue = textObj.value;
var tmpLength = tmpFloatValue.length;
var count = 0;
for (var i = 0; i < tmpLength; i++){
aChar = tmpFloatValue.substring(i,i+1);
if (aChar != "." && !isNumber(aChar)){
alert("请输入合法数字!");
textObj.focus(this);
textObj.select(this);
return false;
}
}
for (var i = 0; i < tmpLength; i++){
aChar = tmpFloatValue.substring(i,i+1);
count = 0;
if (aChar == "."){
count++;
}
}
if (count > 1){
alert("请输入正确的浮点数!");
textObj.focus(this);
textObj.select(this);
return false;
}
return true;
}
上面的是校验输入框中输入的是否是数字
【相关文章:】
如何调用Windows自带的配色控件
js控制页面字体大小
JS代码实现的自动分页效果
关闭弹出窗口刷新父窗口
下拉菜单/列表 跳转 代码
彻底隐藏你HTML网页的源代码
刷新页面随机显示FLASH
一个翻页的JS代码(Javascript)
改善用户体验之密码强度提示
滚动信息示例
【发表评论】【打印此文】【关闭窗口】【点击数: 】
var tmpDateValue = textObj.value;
var tmpLength = tmpDateValue.length;
if (tmpLength == 0){
return true;
}
for (var i = 0; i < tmpLength;i++){
aChar = tmpDateValue.substring(i,i+1);
if(aChar != "-" && (aChar < "0" ¦¦ aChar > "9")) {
alert ("请按照格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
}
if ((tmpLength < 8 ¦¦ tmpLength > 10) && tmpLength != 0) {
alert ("请按照格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
for (var j= 0; j < 4;j++){
aChar = tmpDateValue.substring(j,j+1);
if(aChar < "0" ¦¦ aChar > "9") {
alert ("请按照格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
}
if (tmpDateValue.substring(4,5) != "-" ¦¦ tmpDateValue.substring(5,6) == "-"){
alert ("请按规定格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
if (tmpLength == 8){
if (tmpDateValue.substring(6,7) != "-" ¦¦ tmpDateValue.substring(7,8) == "-" ){
alert ("请按规定格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
}
if (tmpLength == 9){
if (tmpDateValue.substring(8,9) == "-" ){
alert ("请按规定格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
}
if (tmpLength == 10){
if (tmpDateValue.substring(7,8) != "-" ¦¦ tmpDateValue.substring(6,7) == "-" ¦¦ tmpDateValue.substring(8,9) == "-" ¦¦ tmpDateValue.substring(9,10) == "-" ){
alert ("请按规定格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
}
var count=0;
for (var k = 0; k < tmpLength;k++){
aChar = tmpDateValue.substring(k,k+1);
if(aChar == "-") {
count++;
}
}
if (count!=2){
alert("请按照格式输入日期!(yyyy-mm-dd)");
textObj.focus(this);
textObj.select(this);
return false;
}
return true;
}
上面的是校验输入框内是否是日期,且格式是由数字和"-"符号构成;符合"yyyy-m-d"或"yyyy-m-dd"或"yyyy-mm-d"或"yyyy-mm-dd"的格式(即textObj.value.length为8、9、10中的一种)
function isFloat(textObj){
var tmpFloatValue = textObj.value;
var tmpLength = tmpFloatValue.length;
var count = 0;
for (var i = 0; i < tmpLength; i++){
aChar = tmpFloatValue.substring(i,i+1);
if (aChar != "." && !isNumber(aChar)){
alert("请输入合法数字!");
textObj.focus(this);
textObj.select(this);
return false;
}
}
for (var i = 0; i < tmpLength; i++){
aChar = tmpFloatValue.substring(i,i+1);
count = 0;
if (aChar == "."){
count++;
}
}
if (count > 1){
alert("请输入正确的浮点数!");
textObj.focus(this);
textObj.select(this);
return false;
}
return true;
}
上面的是校验输入框中输入的是否是数字
【相关文章:】
如何调用Windows自带的配色控件
js控制页面字体大小
JS代码实现的自动分页效果
关闭弹出窗口刷新父窗口
下拉菜单/列表 跳转 代码
彻底隐藏你HTML网页的源代码
刷新页面随机显示FLASH
一个翻页的JS代码(Javascript)
改善用户体验之密码强度提示
滚动信息示例
【发表评论】【打印此文】【关闭窗口】【点击数: 】
★好玩的休闲小游戏★
网友评论:
数据载入中,请稍后……
