为什么正则表达式老是提示出错?在线等待。。。。。

KJ_Wang 2008-01-19 07:17:45


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
Untitled Page
</title>

<script language="javascript" type="text/javascript">
<!--
function NumericTextBox_KeyPress()
{
var keycode=event.keyCode;
if(!((keycode>47&&keycode<58)||(keycode==46)))
{
event.keyCode= 0;
}
}
function NumericTextBox_KeyUp(ctrl)
{
var str= ctrl.value;
var numerics= str.split(".");
if(numerics.length==3)
{
ctrl.value=str.substring(0,str.length-1);
}
}
function NumericTextBox_Paste()
{
var b=clipboardData.getData('text');
var c=b.match(^([+-]?)\\d*\\.?\\d+$);
alert(c);
return c;
}
-->
</script>
</head>
<body>
<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJMTQ3Njk1NDk2ZGQ1SH1k7gz1K270HTDE26+37OCxLg==" />
</div>

<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>


<script src="/AjaxToolKitTest/WebResource.axd?d=i0KPl_q3uG-64BKBHtcp1g2&t=633222307060000000" type="text/javascript"></script>


<script type="text/javascript">
<!--
var __cultureInfo = '{"name":"zh-CN","numberFormat":{"CurrencyDecimalDigits":2,"CurrencyDecimalSeparator":".","IsReadOnly":true,"CurrencyGroupSizes":[3],"NumberGroupSizes":[3],"PercentGroupSizes":[3],"CurrencyGroupSeparator":",","CurrencySymbol":"¥","NaNSymbol":"非数字","CurrencyNegativePattern":2,"NumberNegativePattern":1,"PercentPositivePattern":1,"PercentNegativePattern":1,"NegativeInfinitySymbol":"负无穷大","NegativeSign":"-","NumberDecimalDigits":2,"NumberDecimalSeparator":".","NumberGroupSeparator":",","CurrencyPositivePattern":0,"PositiveInfinitySymbol":"正无穷大","PositiveSign":"+","PercentDecimalDigits":2,"PercentDecimalSeparator":".","PercentGroupSeparator":",","PercentSymbol":"%","PerMilleSymbol":"‰","NativeDigits":["0","1","2","3","4","5","6","7","8","9"],"DigitSubstitution":1},"dateTimeFormat":{"AMDesignator":"上午","Calendar":{"MinSupportedDateTime":"\/Date(-62135596800000)\/","MaxSupportedDateTime":"\/Date(253402271999999)\/","AlgorithmType":1,"CalendarType":1,"Eras":[1],"TwoDigitYearMax":2029,"IsReadOnly":true},"DateSeparator":"-","FirstDayOfWeek":0,"CalendarWeekRule":0,"FullDateTimePattern":"yyyy\u0027年\u0027M\u0027月\u0027d\u0027日\u0027 H:mm:ss","LongDatePattern":"yyyy\u0027年\u0027M\u0027月\u0027d\u0027日\u0027","LongTimePattern":"H:mm:ss","MonthDayPattern":"M\u0027月\u0027d\u0027日\u0027","PMDesignator":"下午","RFC1123Pattern":"ddd, dd MMM yyyy HH\u0027:\u0027mm\u0027:\u0027ss \u0027GMT\u0027","ShortDatePattern":"yyyy-M-d","ShortTimePattern":"H:mm","SortableDateTimePattern":"yyyy\u0027-\u0027MM\u0027-\u0027dd\u0027T\u0027HH\u0027:\u0027mm\u0027:\u0027ss","TimeSeparator":":","UniversalSortableDateTimePattern":"yyyy\u0027-\u0027MM\u0027-\u0027dd HH\u0027:\u0027mm\u0027:\u0027ss\u0027Z\u0027","YearMonthPattern":"yyyy\u0027年\u0027M\u0027月\u0027","AbbreviatedDayNames":["日","一","二","三","四","五","六"],"ShortestDayNames":["日","一","二","三","四","五","六"],"DayNames":["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],"AbbreviatedMonthNames":["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月",""],"MonthNames":["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月",""],"IsReadOnly":true,"NativeCalendarName":"公历","AbbreviatedMonthGenitiveNames":["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月",""],"MonthGenitiveNames":["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月",""]}}';// -->
</script>

<script src="/AjaxToolKitTest/ScriptResource.axd?d=5RCCoy5nQTCCikOaOPl47RbyxRTA1Zmv0tEYs03UBrxNpQLRROU49lvbnlUy2ptC2ih-Tu9x04uZ14XP2cshiAji_Ne8XX1BKeezhfk_Ub01&t=633228688040000000" type="text/javascript"></script>
<script src="/AjaxToolKitTest/ScriptResource.axd?d=5RCCoy5nQTCCikOaOPl47RbyxRTA1Zmv0tEYs03UBrxNpQLRROU49lvbnlUy2ptC2ih-Tu9x04uZ14XP2cshiFQsnixxAj_WxCrqDPdw5rY1&t=633228688040000000" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('form1'));
Sys.WebForms.PageRequestManager.getInstance()._updateControls([], [], [], 90);
//]]>
</script>

<div>
<input name="NumericTextBox1" type="text" id="NumericTextBox1" onkeypress="NumericTextBox_KeyPress()" onkeyup="NumericTextBox_KeyUp(this)" onpaste="return NumericTextBox_Paste()" />
</div>

<div>

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgKOl8OuAQLpp5CoCdTsr5rjJY4WeG9rDZlE6PLJaLZE" />
</div>

<script type="text/javascript">
<!--
Sys.Application.initialize();
// -->
</script>
</form>
</body>
</html>
就这条语句最烦人,从组件中注册出来的,怎么都通不过,老是提示语法错误
var c=b.match(^([+-]?)\\d*\\.?\\d+$);
哪位高手指点指点!!!!!超急用!!!!!
...全文
58 点赞 收藏 6
写回复
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
KJ_Wang 2008-01-19
多谢
回复
-空军- 2008-01-19
match()方法用于从字符串中查找指定的值,它返回的是与正则表达式匹配的字符串。如果字符串中没有可匹配的值,返回null。

如果想返回bool值,可以试试:

var c = (b.match("^([-+]?)\\d*\\.?\\d+$") != null);
回复
KJ_Wang 2008-01-19
如果将^([-+]?)\\d*\\.?\\d+$放在双引号内无语法错误,但返回的不是bool值,而是null,
如果不放在双引号内,则出现语法错误,你这样说根本不可能做到。
回复
KJ_Wang 2008-01-19
这个不行啦,我试过了
回复
-空军- 2008-01-19
var c = b.match("^([-+]?)\\d*\\.?\\d+$");

"^([-+]?)\\d*\\.?\\d+$"应该把-放在+前面。
回复
-空军- 2008-01-19
var c=b.match("^([+-]?)\\d*\\.?\\d+$"); 
回复
发动态
发帖子
组件/控件开发
创建于2007-09-28

8833

社区成员

.NET技术 组件/控件开发
申请成为版主
社区公告
暂无公告