473,698 Members | 2,339 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Identifying invalid char position using RegExp

Good morning.

I would like to use one or more RegExps to validate country names as having
the first and last words beginning with an uppercase letter, intermediate
words beginning with either uppercase or lowercase, and all other characters
being lowercase characters. For example:

Turks and Caicos

The difficult part is that I want to obtain save the string positions of the
invalid characters in an array, rather than just obtain a true or false
value.

Can anybody with more experience with Regular Expressions than me suggest
some code, sites, or approaches.

Thanks,
Ron
Jul 23 '05 #1
5 1568
Ron Brennan wrote on 20 nov 2004 in comp.lang.javas cript:
Good morning.
Not for us overhee in Europe ;-)

I would like to use one or more RegExps to validate country names as
having the first and last words beginning with an uppercase letter,
intermediate words beginning with either uppercase or lowercase, and
all other characters being lowercase characters. For example:

Turks and Caicos

The difficult part is that I want to obtain save the string positions
of the invalid characters in an array, rather than just obtain a true
or false value.


simple testing is a Regex job:

s = 'Turks and Caicos'
alert(/^[A-Z][a-z]+ ([A-Za-z][a-z]+ )*[A-Z][a-z]+$/.test(s))

however your question is more a looping afair, not simple regex:

=============== ========

yourtest('Turks and Caicos')
yourtest('turKs anD cCaicos')
yourtest('turks And cCaicoS')

function yourtest(s){
stest = ' '
for (i=0;i<s.length ;i++){
LastIsSpace = / /.test(stest)
stest = s.substr(i,1)
if (
i==0 &&
/[^A-Z]/.test(stest)
) // test first letter
document.write( i+' ff '+stest+'<br>')
else if (
LastIsSpace &&
/[^A-Z ]/.test(stest) &&
!/ /.test(s.substr( i,999))
) // test first letter last word
document.write( i+' ff '+stest+'<br>')
else if (
!LastIsSpace &&
/[^a-z ]/.test(stest)
) // test nonfirst letters
document.write( i+' FF '+stest+'<br>')
else // OK
document.write( i+' OK '+stest+'<br>')
}
document.write( '<br><br>')
}

=============== ========

Please make your own array.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #2
Yes, that appears to be exacly what I wanted. I'll confirm that it works in
my application when I finish.

Thanks to Evertjan for the generous contribution of time and effort.

Ron

Jul 23 '05 #3
JRS: In article <RO************ ********@magma. ca>, dated Sat, 20 Nov
2004 10:16:27, seen in news:comp.lang. javascript, Ron Brennan
<rb******@magma .ca> posted :

I would like to use one or more RegExps to validate country names as having
the first and last words beginning with an uppercase letter, intermediate
words beginning with either uppercase or lowercase, and all other characters
being lowercase characters. For example:

Turks and Caicos


That policy fails for, among others,
British Virgin Islands
Campione d'Italia
Saint-Pierre et Miquelon
Turks and Caicos Islands
British Antarctic Territory
British Indian Territory
French Southern Territories
Juan de Nova Island
South Georgia and the South Sandwich Islands
Peñón de Vélez de la Gomera
and, of course,
the United States of America
Stato della Citta del Vaticano
the United Kingdom of Great Britain and Northern Ireland
Poblacht na h'Eireann
La Republique de la Cote d'Ivoire
Daulat Libiya al-'Arabiya al-Ishtrakiya al-Jumhuriya
Zhonghua Renmin Gongheguo
Chung-hua Min Kuo
and others.

Including Lord Howe Island; a place of interest that Win98 seems not to
be configurable for.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 23 '05 #4
That policy fails for, among others,
British Virgin Islands
Campione d'Italia
Saint-Pierre et Miquelon
Turks and Caicos Islands
British Antarctic Territory
British Indian Territory
French Southern Territories
Juan de Nova Island
South Georgia and the South Sandwich Islands
Peñón de Vélez de la Gomera
and, of course,
the United States of America
Stato della Citta del Vaticano
the United Kingdom of Great Britain and Northern Ireland
Poblacht na h'Eireann
La Republique de la Cote d'Ivoire
Daulat Libiya al-'Arabiya al-Ishtrakiya al-Jumhuriya
Zhonghua Renmin Gongheguo
Chung-hua Min Kuo
and others.

Including Lord Howe Island; a place of interest that Win98 seems not to
be configurable for.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. © Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm

etc.

The policy was a prototype I tentatively adoped when I didn't immediately
think of any of the many cases you cited. Obviously the policy has to be
rewritten and probably requires as part of it an enumeration of exceptions.
I'll see what I can come up with tomorrow and post it here for review.

Jul 23 '05 #5


Have you considered

1) doing this at the server
2) using 'dependent' listboxes at the client

Both would present the user with valid choices, rather than attempting
an algorithm to validate such a wide array of possibilities.. ..

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #6

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

Similar topics

2
2360
by: Ron Brennan | last post by:
Good morning. I would like to use one or more RegExp to validate country names as having the first and last words beginning with an uppercase letter, intermediate words beginning with either uppercase or lowercase, and all other characters being lowercase characters. The difficult part is that I want to obtain save the string positions of the invalid characters in an array, rather than just obtain a true or false value. Can anybody...
1
5175
by: hokiegal99 | last post by:
This is not really a Python-centric question, however, I am using Python to solve this problem (as of now) so I thought it appropiate to pose the question here. I have some functions that search for files that contain certian strings and if the files found to have these string do not already have a filename extension (such as '.doc' or '.xls') the function will append that to the files and rename them. So, if a file named 'report' was...
1
8250
by: Neil Morris | last post by:
Hi I have the following code that lists first names of people who's surnames are 'Morris'. What I am trying to do is search for first names that don't start at the beginning of the line ie. have the '' in the regExp object, but 'Neil' is matched even though it is next to(?) the start of line char(?) or should I say 'Neil' is the first 'word' of the string? here's the code <html>
3
2127
by: Christopher Weaver | last post by:
I want to set a value in a specific field in the current row of a DataSet. This seems like the most basic thing to do but I can't find the syntax for identifying the current row. IOW, I can do this: SomeRow = 'value'; But how do I set SomeRow to the row that the user is currently viewing?
2
3044
by: Ste | last post by:
I generated a class from an XSD using XSDObjectGen, when i try to create an xml serialized string from it i get an invalid char in position 1,1 The code i use to serialise the object is pasted below.. lifted from http://www.dotnetjohn.com/articles.aspx?articleid=173 The char at position 1 is displayed as a "?" so some encoding is taking place.. it has a hex value is 0xFeFF Can anyone spot an obvious mistake??
7
3446
by: Csaba Gabor | last post by:
I need to come up with a function function regExpPos (text, re, parenNum) { ... } that will return the position within text of RegExp.$parenNum if there is a match, and -1 otherwise. For example: var re = /some(thing|or other)?.*(n(est)(?:ed)?.*(parens) )/ var text = "There were some nesting parens in the test"; alert (regExpPos (text, re, 3));
1
8026
by: Java Guy | last post by:
I'm trying to view a web page. IE tells me there are (Java?) errors on the page. Here they are: Line: 15 Char: 7 Error: Wrong number of arguments or invalid propert assignment Code: 0 URL: http://(address.of.my.webcam):port/LiveView.html and
10
4499
by: Frankie | last post by:
It appears that System.Random would provide an acceptable means through which to generate a unique value used to identify multiple/concurrent asynchronous tasks. The usage of the value under consideration here is that it is supplied to the AsyncOperationManager.CreateOperation(userSuppliedState) method... with userSuppliedState being, more or less, a taskId. In this case, the userSuppliedState {really taskId} is of the object type,...
6
8375
by: =?ISO-8859-1?Q?Une_B=E9v?==?ISO-8859-1?Q?ue?= | last post by:
I wanted to test userAgent by a Regexp the goal : true if UA contains "AppleWebKit/528+ " or "AppleWebKit/525.12+ " note the final "+" false otherwise then i wrote :
0
8603
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
9157
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
9027
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...
1
8895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6518
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
4369
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
3046
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
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
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.