<SCRIPT LANGUAGE="JavaScript">
<!--
var pattern=/ /g;
alert(pattern.test("xhbmj"));
//-->
</SCRIPT>
<!--
var pattern=/ /g;
alert(pattern.test("xhbmj"));
//-->
</SCRIPT>
解决方案 »
- 正则表达式
- 关于得到下拉框ID的问题。
- ●●●●●●●●●●●●●●●●●●●●●●●●●●●很简单的一段代码 怎么出错了??????
- javascript 字符串中如何引用变量? 字符串是struts2 表达式。
- 如何实现像windows那样的字符串复制功能?
- 在jsp中怎样用javascript来删除一个文件?
- 仅仅在窗口关闭时才执行的一个脚本怎么做?
- 如何实现frame的隐藏和显示?火急!
- 请问通过网页查询数据库时,网页显示:正在处理中,获取记录后才显示结果,这个应该怎么做呢?
- 感觉做javascript前端的人脾气很大
- 用showModalDialog()显示的网页,如何让它的关闭按钮不显示或者灰掉?
- 秋水,有没有见过这个好东西?
alert((/^[^ ]* {1,1}[^ ]*$/).test("asdfasdf asdfa"));
alert((/^[^ ]* {1,1}[^ ]*$/).test("asdfa sdf asdfa"));
</script>妈呀,累死我啦。
//判断字符串有且只能有一个空格
function check(str)
{
if(/^[^\s]*\s[^\s]*$/g.test(str))
{ alert("格式正确");}
else
{alert("必须有且只能有1个空格");}
}
check("[sdf]");
check("[asdf ]");
check("[ asdf]");
check("[sf sdf]");
check("[ sdf ]");
check("[ df df]");
</script>
//判断字符串有且只能有一个空格,不能以空格开头
function check(str)
{
if(/^[^\s]+\s[^\s]*$/g.test(str))
{ alert("格式正确");}
else
{alert("不能以空格开头,必须有且只能有1个空格");}
}
check("[sdf]");
check("[asdf ]");
check("[ asdf]");
check("[sf sdf]");
check("[ sdf ]");
check("[ df df]");
</script>
//判断字符串有且只能有一个空格,不能以空格开头
function check(str)
{
if(!/\s/.test(str)){
alert("没有空格");
}else{
str=str.replace(/\s/,"")
if(!/\s/.test(str)){
alert("只有一个空格");
}else{
alert("多于一个空格");
}
}
}
check("[sdf]");
check("[asdf ]");
check("[ asdf]");
check("[sf sdf]");
check("[ sdf ]");
check("[ df df]");
</script>
//判断字符串有且只能有一个空格,不能以空格开头
function check(str)
{
if(/\s/.test(str)&&!/\s/.test(str.replace(/\s/,""))){
alert("格式正确");
}else{
alert("不能以空格开头,必须有且只能有1个空格");
}
}
check("[sdf]");
check("[asdf ]");
check("[ asdf]");
check("[sf sdf]");
check("[ sdf ]");
check("[ df df]");
</script>