473,722 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JS Enabled But No RegExp Support?

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
Dec 1 '05 #1
26 2132
Matt Kruse wrote:
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?


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 customValidatio n='custom(this) '> ).

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

Dec 1 '05 #2
VK
function isDigits(val) {
if (window.RegExp) {
return !(val.search(/^\d+$/)==-1);
}
else {
/* NOP */
// or
// alert("Where did you get this junk?");
}
}

The first is nicer, the second is more informative and stimulating to
the end user.

Also Konqueror 1.x will very probably crash right on the
(window.RegExp) check.

It seems to crash randomly at the moment you're trying to use
JavaScript for DOM access. This alone kills the imperative "Support for
each and every one". An averagely bad browser producer will always win
against of a good developer however good the developer would be.

About PDA and web-phones: it is too early yet to worry about. IMHO you
should wait until it's clear who's dominating. Did you ever try to use
say an Nokia accessory for Siemens? Or a Siemens charger for Ericsson?
That exact situation with the software: a fight to death, only later
the survivers will start to cooperate to keep away newcomers. I passed
this with WML for the first wave of GPRS phones. The first year one
would have to make a separate solution for each and every phone. And
now WML is pretty set (but getting out of use though).
From my personal experience (I'm having Toshiba with Pocket PC 2002,

now Pocket PC 2005) you always can count on Netscape 2.0 JavaScript
(without document.write( ) though) and XML/XSLT The latter is a mistery
to me but any prodicer seems to feel obligated to have it. HTMLDocument
DOM will be most probably in absence or cut to a misery state (another
mistery).
All this based on my personal experience and observations therefore it
can be factually, logically and grammatically incorrect.

Dec 1 '05 #3
Matt Kruse wrote on 01 dec 2005 in comp.lang.javas cript:
return !(val.search(/^\d+$/)==-1);


Your real Q seems to be answered,
but the above line is too complex for me, Mat.

would this do:

return (val.search(/^\d+$/)==0);

or even better[?]

return !/\D/.test(val);


--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Dec 1 '05 #4
Matt Kruse wrote:
Are there any current browsers that have Javascript support, but not
RegExp support?
Probably not.
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) {
Do not infer that `window' refers to the Global Object because
it does so in some HTML user agents. The proper feature test
(JavaScript 1.1, JScript 1.0, ECMAScript Ed. 1) is

if (typeof RegExp == "function")
return !(val.search(/^\d+$/)==-1);
Try

return (new RegExp("^\\d+$" )).test(val);

I would recommend a RegExp object literal instead of calling
the constructor, but you were asking for a general method where
the latter cannot be assumed.
}
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).
Yes. For this specific method, I would use a `for' loop,
String.prototyp e.charAt() and String.prototyp e.charCode().
And if that's the case, then why even include the duplicate regexp
code to begin with?
Because it is more efficient than the brute-force method, where supported.
[...]
Just curious what others have concluded, and if the "js enabled but no
RegExp support" condition is even realistic?


According to my findings, RegExp literals are supported since JavaScript 1.3
(NN 4.06, 1998), JScript 3.0 (IE 4.0) and ECMAScript Edition 3 (December
1999); the RegExp object and constructor is apparently supported since
JavaScript 1.2 (NN 4.0, June 1997), JScript 3.0 (IE 4.0) and ECMAScript
Edition 3.
PointedEars
Dec 2 '05 #5
Thomas 'PointedEars' Lahn wrote:
Matt Kruse wrote:
return !(val.search(/^\d+$/)==-1);


Try

return (new RegExp("^\\d+$" )).test(val);


Or probably faster

return !(new RegExp("[^\\d]")).test(va l);
PointedEars
Dec 2 '05 #6
Thomas 'PointedEars' Lahn wrote:
Do not infer that `window' refers to the Global Object because
it does so in some HTML user agents.


Name a single exception - then I might agree with you.
And if that's the case, then why even include the duplicate regexp
code to begin with?

Because it is more efficient than the brute-force method, where
supported.


Perhaps, but the need to write, debug, and test two code paths when a single
code path would work for all cases may over-ride the (very) small
performance increase one might see by using regular expressions.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Dec 2 '05 #7
Matt Kruse wrote:
Thomas 'PointedEars' Lahn wrote:
Do not infer that `window' refers to the Global Object because
it does so in some HTML user agents.


Name a single exception - then I might agree with you.


I do not require your agreement for my statement to be correct.
And if that's the case, then why even include the duplicate regexp
code to begin with?

Because it is more efficient than the brute-force method, where
supported.


Perhaps, but the need to write, debug, and test two code paths when a
single code path would work for all cases may over-ride the (very) small
performance increase one might see by using regular expressions.


I did not say you have to.
PointedEars
Dec 2 '05 #8
Thomas 'PointedEars' Lahn <Po*********@we b.de> wrote in
news:17******** ********@Pointe dEars.de:
Matt Kruse wrote:
Thomas 'PointedEars' Lahn wrote:
Do not infer that `window' refers to the Global Object because
it does so in some HTML user agents.


Name a single exception - then I might agree with you.


I do not require your agreement for my statement to be correct.


From http://www.webreference.com/js/column80/6.html:

"The global object is the browser window object,
the one you query the location of by window.location ()."

For all practical purposes, the global object is the window object.

When you name an actual implementation of the global object that is not
browser window-based, then your statement will be more than just what it is
now: pedantic.

Dec 4 '05 #9
Patient Guy wrote:
Thomas 'PointedEars' Lahn <Po*********@we b.de> wrote [...]
Matt Kruse wrote:
Thomas 'PointedEars' Lahn wrote:
Do not infer that `window' refers to the Global Object because
it does so in some HTML user agents.
Name a single exception - then I might agree with you. I do not require your agreement for my statement to be correct.


From http://www.webreference.com/js/column80/6.html:

"The global object is the browser window object,
the one you query the location of by window.location ()."


Quoting some thing that calls itself "reference" does not prove anything.
For all practical purposes, the global object is the window object.
That depends on what you call "practical purpose". _Client-side_
scripting in a _(X)HTML_ DOM environment: _probably_ yes, due to history.
Client-side scripting in another environment: not necessarily, and there
are examples of the opposite. Server-side scripting: _no_.
When you name an actual implementation of the global object that is not
browser window-based, then your statement will be more than just what it
is
now: pedantic.


No, examples where it does not apply have already been posted here before.
One just needs to be willing to read and learn. And to know the basics:
There are no windows where they cannot be displayed, hence it would be not
reasonable to have a `window' reference there, let alone let it refer the
Global Object.
PointedEars
Dec 4 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
5482
by: Mark Johnson | last post by:
Is there a shorthand for this: <xsl:when test="$day2 or $day2 or $day2">
12
2576
by: confused | last post by:
After expressing my interest in expanding my new knowledge of HTML and CSS into the wild realm of JavaScript, I was advised that it is wiser to avoid it, since not all browsers are use it or are enabled to read it. After searching for other opinions on the web, I found that some estimate that the frequency of browsers that can read JS currently is better than 90% -- that is certainly workable for me! Do you good people have any thoughts...
13
8477
by: Alex Molochnikov | last post by:
Is there any way to find out programmatically if Javascript is supported/enabled in a browser? By "programmatically" I mean on the Java servlet side. TIA Alex Molochnikov Gestalt Corporation
3
7067
by: zzzxtreme | last post by:
hello i have this function to check date (not mine) function (s_date) { // check format if (!re_dt.test(s_date)) return false; // check allowed ranges if (RegExp.$1 > 31 || RegExp.$2 > 12) return false;
4
7477
by: Jon Maz | last post by:
Hi All, I want to strip the accents off characters in a string so that, for example, the (Spanish) word "práctico" comes out as "practico" - but ignoring case, so that "PRÁCTICO" comes out as "PRACTICO". What's the best way to do this? TIA,
7
1908
by: arno | last post by:
Hi, I want to search a substring within a string : fonction (str, substr) { if (str.search(substr) != -1) { // do something } }
9
34786
by: Laphan | last post by:
Hi All I'm using the below to limit the input into a text box to just letters, numbers, hyphens and full stops, but I also need to allow the backspace, delete and arrow keys to come through. How can I do this? <script language="JavaScript" type="text/javascript"> <!-- function onKeyPressBlockNumbers(e) {
0
1153
by: problematic | last post by:
Hello guys Actually i dont know does mysql support prepare with regexp but i have this query. prepare stm from "select count(id) as total from products where content regexp ']?]' "; set @a = "keyword"; execute stm using @a; it gives error i think it is about usage ? in regexp condition but i dont know how to use ? in regexp. thanks i am using MySQL 5.0.18 on windows xp+sp2
6
8380
by: Brandon McCombs | last post by:
Hello, I have a Form that contains some configuration information. One of the settings is for SSL. There is a checkbox that I want to check to make 2 textboxes un-editable so that a user can type information into the textboxes. If the SSL checkbox is unchecked the 2 textboxes should become readonly again. I have my event handler properly setup to listen for the CheckStateChanged event. My debug print statement prints out information
0
8863
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8739
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5995
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4502
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.