用JavaScript判断字符串长度
来源:asp之家 发布时间:2009-10-29 12:15:00
标签:JavaScript,字符串,长度
判断字符串长度函数:
<SCRIPT LANGUAGE="JavaScript">
<!--
function a()
{
var totallength=0;
for (var i=0;i<document.forma.sUserName.value.length;i++)
{
var str=document.forma.sUserName.value;
var intCode=str.charCodeAt(i);
if (intCode>=0 && intCode<=128) {//continue;
totallength=totallength+1;
}
else {
totallength=totallength+2;
}
} //end for
alert(totallength);
if (totallength<3 wsws totallength>20)
{
document.forma.sUserName.select();
alert("用户名必须是3-20个字符!请重新输入。");
return false;
}
return true;
}
//-->
</SCRIPT>
0
投稿
猜你喜欢
- 介绍与创建型模式类似,工厂模式创建对象(视为工厂里的产品)时无需指定创建对象的具体类。工厂模式定义一个用于创建对象的接口,这个接口由子类决定
- 前言最近在用yolov5参加比赛,yolov5的技巧很多,仅仅用来参加比赛,着实有点浪费,所以有必要好好学习一番,在认真学习之前,首先向yo
- Pycharm打开大文件的时候出现这个错误,根据提示以及百度知道,是因为IDEA对能关联的文件大小做了限制,主要是为了保护内存,默认值为25
- 我们可以使用matplotlib.pyplot.locator_params()来控制刻度线 * 的行为。 即使通常会自动确定标记点的位置,
- 本文是总结的一点经验之谈啥是data-key微信小程序推出 data- 属性——自定义属性,为了更好的进行数据传递。总结来说,data-ke
- 一、创建TensorRT有以下几个步骤:1.用TensorRT中network模块定义网络模型2.调用TensorRT构建器从网络创建优化的
- 本文实例讲述了ThinkPHP框架下微信支付功能总结。分享给大家供大家参考,具体如下:摘要此文主要为个人解决 ThinkPHP3.2.3 下
- --创建链接服务器 exec sp_addlinkedserver &
- 本文实例为大家分享了Android九宫格图片展示的具体代码,供大家参考,具体内容如下<!DOCTYPE html><htm
- Oracle是应用最广的大型数据库,而在范式下进行Oracle数据库设计则可以大大减少数据冗余,使数据库维护更方便,可惜范式下的数据表一般不
- TeX 排版中文字体嵌入问题,兼谈不拘小节的中文字体设计原文:http://yulewang.spaces.live.com/blog/cn
- 有1张表, Wages 表 ------------------------------------------- Emp_id&
- 如下所示:import re# 过滤不了\\ \ 中文()还有————r1 = u'[a-zA-Z0-9'!"#$
- 从XML中读取数据到内存的实例: public clsSi
- 在Python中可以通过在属性变量名前加上双下划线定义属性为私有属性,如例子:#! encoding=UTF-8 class A:
- 前言本章介绍pandas中的缺失数据,主要内容有:pandas中对np.nan的操作: 统计 、 删除 、 填充 、 插值 pan
- 我就废话不多说了,直接上代码吧!a=[[1,2,3],[4,5][6,7]["a","b""
- 在数据库中执行建表语句CREATE TABLE `sys_acl` ( `id` int(11) NOT NULL AUTO_INCREME
- 知识点文件读写基础语法字符串处理字符拼接代码解析导入模块import platformimport stringimport random将
- 常见的数据库对象对象描述表(TABLE)表是存储数据的逻辑单元,以行和列的形式存在,列就是字段,行就是记录数据字典就是系统表,存放数据库相关