JS启用但没有RegExp支持? [英] JS Enabled But No RegExp Support?

查看:64
本文介绍了JS启用但没有RegExp支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前有没有Javascript支持的浏览器,但没有RegExp

支持?

例如,手机浏览器,blackberrys或其他最小支持浏览器?

我知道使用Netscape 3的人会属于这个类别,例如

,但这不再是一个现实的情况。


如果存在这样的情况,那么如果浏览器缺少这些条件,你们如何使用

正则表达式处理验证?


例如:


函数isDigits(val){

if(window.RegExp){

return!(val。搜索(/ ^ \d + $ /)== - 1);

}

else {

//没有regexp支持

// ????

}

}


如果没有RegExp支持,那么应该粗暴使用indexOf,

substr等使用-force方法? (不是针对这种特定的方法,而是一般情况)。

如果是这种情况,那么为什么甚至包括重复的正则表达式代码以

开头?


或者如果不应该使用蛮力方法,那么应该返回什么?b $ b?未定义?空值?然后该方法变得不那么有用,因为它不会像用户期望的那样始终如一地返回true或false。

一个isX返回我不知道的方法使得b $ b验证表格等非常困难。


只是好奇其他人的结论,如果js已启用但没有

RegExp支持条件是否真实?


-

Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com

Are there any current browsers that have Javascript support, but not RegExp
support?
For example, cell phone browsers, blackberrys, or other "minimal" browsers?
I know that someone using Netscape 3 would fall into this category, for
example, but that''s not a realistic situation anymore.

And if such a condition exists, then how do you guys handle validation using
regular expressions, if the browser lacks them?

For example:

function isDigits(val) {
if (window.RegExp) {
return !(val.search(/^\d+$/)==-1);
}
else {
// No regexp support
// ????
}
}

If no RegExp support, then should brute-force methods be used using indexOf,
substr, etc? (not for this specific method, but the general case).
And if that''s the case, then why even include the duplicate regexp code to
begin with?

Or if the brute-force method should not be used, then what should be
returned? undefined? null? Then the method becomes less useful, because it
doesn''t return true or false consistently like a user might expect. Having
an "isX" method that returns "I don''t know" makes it very difficult to
validate forms, etc :)

Just curious what others have concluded, and if the "js enabled but no
RegExp support" condition is even realistic?

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com

推荐答案

/)== - 1);

}

else {

//没有正则表达式支持

// ????

}

}


如果没有RegExp支持,那么应该使用indexOf,

substr等使用暴力方法吗? (不是针对这种特定的方法,而是一般情况)。

如果是这种情况,那么为什么甚至包括重复的正则表达式代码以

开头?


或者如果不应该使用蛮力方法,那么应该返回什么?b $ b?未定义?空值?然后该方法变得不那么有用,因为它不会像用户期望的那样始终如一地返回true或false。

一个isX返回我不知道的方法使得b $ b验证表格等非常困难。


只是好奇其他人的结论,如果js已启用但没有

RegExp支持条件是否真实?


-

Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
/)==-1);
}
else {
// No regexp support
// ????
}
}

If no RegExp support, then should brute-force methods be used using indexOf,
substr, etc? (not for this specific method, but the general case).
And if that''s the case, then why even include the duplicate regexp code to
begin with?

Or if the brute-force method should not be used, then what should be
returned? undefined? null? Then the method becomes less useful, because it
doesn''t return true or false consistently like a user might expect. Having
an "isX" method that returns "I don''t know" makes it very difficult to
validate forms, etc :)

Just curious what others have concluded, and if the "js enabled but no
RegExp support" condition is even realistic?

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


Matt Kruse写道:
Matt Kruse wrote:
目前有没有Javascript的浏览器支持,但不是RegExp
支持?


对于工作,我们必须支持使用IE 4.01并且没有正则表达式的Windows CE 3.0手持设备(又名HPC

Professional)。 br />
当前的CE有一个更好的浏览器。

如果存在这样的情况,那么你们如何处理使用
正则表达式的验证,如果浏览器缺少它们吗?
Are there any current browsers that have Javascript support, but not RegExp
support?
For work, we have to support Windows CE 3.0 handheld devices (aka HPC
Professional) that use pretty much IE 4.01, and no regular expressions.
The current CE has a far better browser, though.
And if such a condition exists, then how do you guys handle validation using
regular expressions, if the browser lacks them?




起初很痛苦,但现在我们有一个验证库

例程。当您离开每个字段时,标准函数会自动验证字段(或字段组)对照该字段的属性(例如< input required =" " timeField ="">)或通过调用

自定义验证例程(< input customValidation =''custom(this)''>)。


但这是我们的负担:-)

Kev



It was a pain at first, but now we have a library of validation
routines. As you leave each field, a standard function automatically
validates the field (or group of fields) against attributes of that
field (such as <input required="" timeField=""> ) or by calling a
custom validation routine (<input customValidation=''custom(this)''> ).

But that''s our burden to bear :-)
Kev


function isDigits(val ){

if(window.RegExp){

return!(val.search(/ ^ \d +
function isDigits(val) {
if (window.RegExp) {
return !(val.search(/^\d+


这篇关于JS启用但没有RegExp支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆