473,778 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript - regular expression - foreign characters

i have this function:

------------------------------------------------------------
function isAlfaNumeric(v nos,space) {
if (space==false) {
validRegExp = /^[a-zA-Z0-9]{0,}$/;
}
else {
validRegExp = /^[a-zA-Z0-9\s]{0,}$/;
}
return vnos.search(val idRegExp)
}
-------------------------------------------------------------

the function is checking if the string "vnos" contains any non-alfanumeric
characters... it works fine except it returns true if the string contains
my country characters like ž,š.....i tried to do the following

validRegExp = /^[a-zA-Z0-9žš]{0,}$/; and also

validRegExp = /^[a-zA-Z0-9\ž\š]{0,}$/; but result was the same

Does anyone know how to check for foreign characters in string using regular
expression??
Jul 20 '05 #1
12 11448
Smash wrote on 20 jan 2004 in comp.lang.javas cript:
function isAlfaNumeric(v nos,space) {
if (space==false) {
validRegExp = /^[a-zA-Z0-9]{0,}$/;
}
else {
validRegExp = /^[a-zA-Z0-9\s]{0,}$/;
}
return vnos.search(val idRegExp)
}
-------------------------------------------------------------

the function is checking if the string "vnos" contains any
non-alfanumeric characters... it works fine except it returns true if
the string contains my country characters like z,s.....i tried to do
the following

validRegExp = /^[a-zA-Z0-9zs]{0,}$/; and also

validRegExp = /^[a-zA-Z0-9\z\s]{0,}$/; but result was the same


for {0,} use +
for 0-9 use \d
\s is all kinds of whitespace, like tabs etc.
use test, if you test for a string

try this:

<SCRIPT>
function isAlfaNumeric(s ,sp) {
r = /^[a-zA-Z\džš]+$/;
rs = /^[a-zA-Z\džš\s]+$/;
return (sp)? rs.test(s) : r.test(s);
};

alert(isAlfaNum eric("12astš",t rue));
alert(isAlfaNum eric("34astš",f alse));
alert(isAlfaNum eric("56as tš",true));
alert(isAlfaNum eric("78as tš",false));
</SCRIPT>

If you want to accept empty strings as true, use:

r = /^[a-zA-Z\džš]*$/;
rs = /^[a-zA-Z\džš\s]*$/;

this on works the other way around, accepts empty strings:

<SCRIPT>
function isAlfaNumeric(s ,sp) {
r = /[^a-zA-Z\džš]/;
rs = /[^a-zA-Z\džš\s]/;
return ! ((sp)? rs.test(s) : r.test(s));
};

alert(isAlfaNum eric("12astš",t rue));
alert(isAlfaNum eric("34astš",f alse));
alert(isAlfaNum eric("56as tš",true));
alert(isAlfaNum eric("78as tš",false));
</SCRIPT>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #2
sm*****@email.s i (Smash) writes:
Does anyone know how to check for foreign characters in string using regular
expression??


I think the safest is to use the \w esacpe, which matches "word characters".
That includes letters, international included, digits and the underscore.
If you can live with that:

if (space==false) {
validRegExp = /^[\w]*$/;
}
else {
validRegExp = /^[\w\s]*$/;
}

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
JRS: In article <72************ *************@p osting.google.c om>, seen
in news:comp.lang. javascript, Smash <sm*****@email. si> posted at Tue, 20
Jan 2004 00:37:31 :-
function isAlfaNumeric(v nos,space) {
if (space==false) {
if (!space) { // or if (space) and swap the rest

Does anyone know how to check for foreign characters in string using regular
expression??

"Foreign" does not mean "non-Anglo"; Americans & British are foreigners
too.

AIUI, a string can contain any Unicode character, and there are tens of
thousands of those, a large proportion of which are letters in some
language or other. Therefore, to test fully for letters outside A-Za-z,
one needs in some form or another either a list of *all* letters or a
list of *all* non-letters, or both.

I don't know Slovenian; but I guess that it has a relatively small
number of non-Anglo letters; those could be listed and tested for, but
that would not be entirely helpful to a Scandinavian visitor.

There *should* be a javascript function to test whether the current font
has a specific glyph for a given character, or for all those in a
string; but AFAIK there is not.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #4
Dr John Stockton wrote on 20 jan 2004 in comp.lang.javas cript:
There *should* be a javascript function to test whether the current font
has a specific glyph for a given character, or for all those in a
string; but AFAIK there is not.


If we had a Regex syntax for a character above-a/below-a/in-a-range-of
certain char number(s), even without the knowledge of the specific font,
that would be nice.

regex.defineran ge('%3','>#80')
regex.defineran ge('%5','>#0',' <#20')

boolean = /aa\%5+bb[^\%3]?/.test(string)
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #5
"Evertjan." <ex************ **@interxnl.net > writes:
If we had a Regex syntax for a character above-a/below-a/in-a-range-of
certain char number(s), even without the knowledge of the specific font,
that would be nice.

regex.defineran ge('%3','>#80') regex.defineran ge('%5','>#0',' <#20')

boolean = /aa\%5+bb[^\%3]?/.test(string)


Try:
var boolean = /aa[\x01-\x1f]+bb[^\x81-\uffff]?/.test(string);
It says true for
var string = "aa\n\rbb\u1268 ";
(which is 7 characters long).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #6
Lasse Reichstein Nielsen wrote on 21 jan 2004 in comp.lang.javas cript:
Try:
var boolean = /aa[\x01-\x1f]+bb[^\x81-\uffff]?/.test(string);
It says true for
var string = "aa\n\rbb\u1268 ";
(which is 7 characters long).


[\x01-\x1f] etc

Nice, never thought of that !

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #7
JRS: In article <8y**********@h otpop.com>, seen in
news:comp.lang. javascript, Lasse Reichstein Nielsen <lr*@hotpop.com >
posted at Tue, 20 Jan 2004 22:47:33 :-
sm*****@email. si (Smash) writes:
Does anyone know how to check for foreign characters in string using regular
expression??


I think the safest is to use the \w esacpe, which matches "word characters".
That includes letters, international included, digits and the underscore.


In MSIE4, it does not match É (E-acute), ä (a-umlait), Å (A-ring); and,
I suppose, others.

A Netscape 1.3 reference page include(s|d) :
Matches any alphanumeric character including the underscore.
Equivalent to [A-Za-z0-9_].

It would be nice to be able to match *any* letter, including non-anglo;
but ISTM that \w is fundamentally matching the characters that normally
appear in identifiers, and there it would be very wrong for that to be
altered.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #8
Dr John Stockton <sp**@merlyn.de mon.co.uk> writes:
In MSIE4, it does not match É (E-acute), ä (a-umlait), Å (A-ring); and,
I suppose, others.


Yes, that was me misremembering. Bummer. I would have been nice with
an escape that matches alphanumeric unicode characters, and not just
ASCII ones, and I though ECMAScript had it. That was apparently
just wishful thinking.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #9
JRS: In article <pt**********@h otpop.com>, seen in
news:comp.lang. javascript, Lasse Reichstein Nielsen <lr*@hotpop.com >
posted at Wed, 21 Jan 2004 18:24:12 :-

Try:
var boolean = /aa[\x01-\x1f]+bb[^\x81-\uffff]?/.test(string);
It says true for
var string = "aa\n\rbb\u1268 ";
(which is 7 characters long).


But for that approach to do the original job in full, one needs to read
the entire Unicode table and decide which squashed spiders are foreign
letters and which are foreign non-letters.

I've seen AJF's Unicode table in HTML; but I don't recall seeing one
written in ISO-7 and intended for simple machine-reading.

http://ppewww.ph.gla.ac.uk/~flavell/...e/unidata.html

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #10

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

Similar topics

4
8213
by: Toffe | last post by:
Hi, I've got a problem with regular expressions and strings containing Swedish characters (åäö). I basically have a PHP script that highlights certain words in a text. I found the code attached below in the commented manual at php.net. It works great for all words that do not contain Swedish characters. The words that do contain åäö will not be highlighted.
1
4182
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make regular expressions easier to create and use (and in my experience as a regular expression user, it makes them MUCH easier to create and use.) I'm still working on formal documentation, and in any case, such documentation isn't necessarily the...
5
2692
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one function to verify the name fields, age, email and gender. My question is: if I create a function for each field like the code below, what would be the best way to organize the functions and call them? Would I need one main function and place...
3
2566
by: Zach | last post by:
Hello, Please forgive if this is not the most appropriate newsgroup for this question. Unfortunately I didn't find a newsgroup specific to regular expressions. I have the following regular expression. ^(.+?) uses (?!a spoon)\.$
1
3408
by: NvrBst | last post by:
I want to use the .replace() method with the regular expression /^ %VAR % =,($|&)/. The following DOESN'T replace the "^default.aspx=,($|&)" regular expression with "": --------------------------------- myStringVar = myStringVar.replace("^" + iName + "=,($|&)", ""); --------------------------------- The following DOES replace it though: --------------------------------- var match = myStringVar.match("^" + iName + "=,($|&)");
27
1769
by: rhaazy | last post by:
I need to write some javascript that will return a date string in the form mm/dd/yyyy. The date needs to be today's date - 30 days. Is there a relatively straight forward way to do this? So far all I can find is a mess of variables for month, day, and year, and combining some date functions together, etc etc. Seems like a lot of work for what should be very simple.
0
9464
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
10122
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
8954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7471
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
6722
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
5368
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...
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.