473,382 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Names in forms

Hi there,

How can I use a regular expression to check that a name in a form field
begins with a capital letter?
Jul 23 '05 #1
12 1295
Steve Darby wrote:
How can I use a regular expression to check that a name in a form
field begins with a capital letter?


var beginsWithCap = /^[A-Z]/.test(Element.name);

Since this does not cover "É", "Ä" etc., I would rather use

var firstChar = Element.name.charAt(0),
beginsWithCap = firstChar.toUpperCase() == firstChar;

ciao, dhgm

Jul 23 '05 #2
JRS: In article <36*************@individual.net>, dated Sat, 29 Jan
2005 21:47:28, seen in news:comp.lang.javascript, Dietmar Meier
<us***************@innoline-systemtechnik.de> posted :
Steve Darby wrote:
How can I use a regular expression to check that a name in a form
field begins with a capital letter?


var beginsWithCap = /^[A-Z]/.test(Element.name);

Since this does not cover "É", "Ä" etc., I would rather use

var firstChar = Element.name.charAt(0),
beginsWithCap = firstChar.toUpperCase() == firstChar;


The OP wrote "a name"; the field might contain something like "dietmar
meier", in which case two checks would be needed.

And he may need to be more careful than that; surnames include such as
O'Brien, McCarthy, Chomondeley-Featherstonehaugh, and "proper" names
include such as Pope Gregory XIII.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 23 '05 #3
Dr John Stockton wrote:
The OP wrote "a name"; the field might contain something like "dietmar
meier", in which case two checks would be needed.
If that's the case, I would suggest

var s = Element.value,
e = 0,
valid = s.replace(
/\b\S/g,
function(a) {
e |= a != a.toUpperCase();
}
), !e;
And he may need to be more careful than that; surnames include such as
O'Brien, McCarthy, Chomondeley-Featherstonehaugh, and "proper" names
include such as Pope Gregory XIII.


On the other hand, "Piet van der Falk", "Karl von und zum Stein", etc.
should be considered as valid names.

ciao, dhgm
Jul 23 '05 #4
Dietmar Meier wrote:

[snip]

var s = Element.value,
e = 0,
valid = s.replace(
/\b\S/g,
function(a) {
e |= a != a.toUpperCase();
}
), !e;


e |= a != a.toUpperCase();

I've stared at this long enough, Dietmar, can you explain what's
happening in this line of code? Specifically,"e |="

Mick
Jul 23 '05 #5
"Mick White" <mw***********@rochester.rr.com> wrote in message
news:9b******************@twister.nyroc.rr.com...
Dietmar Meier wrote:

[snip]

var s = Element.value,
e = 0,
valid = s.replace(
/\b\S/g,
function(a) {
e |= a != a.toUpperCase();
}
), !e;


e |= a != a.toUpperCase();

I've stared at this long enough, Dietmar, can you explain what's
happening in this line of code? Specifically,"e |="

Mick


e = e | (a != a.toUpperCase());

So -e- gets set to 1 if -e- is true (or non-null, or a non-empty string,
or a non-zero number, or not undefined) or -a- is not equal to -a-
converted to uppercase.

He then takes advantage of the fact that the comma operator returns the
value of the last operand to set -valid- to the negated value of -e-.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #6
Grant Wagner wrote:
[snip]


e = e | (a != a.toUpperCase());

So -e- gets set to 1 if -e- is true (or non-null, or a non-empty string,
or a non-zero number, or not undefined) or -a- is not equal to -a-
converted to uppercase.

He then takes advantage of the fact that the comma operator returns the
value of the last operand to set -valid- to the negated value of -e-.


Thanks, Grant, I'll have to investigate the "|" operator
..
Mick
Jul 23 '05 #7
rh
Grant Wagner wrote:
"Mick White" <mw***********@rochester.rr.com> wrote in message
news:9b******************@twister.nyroc.rr.com...
Dietmar Meier wrote:

[snip]

var s = Element.value,
e = 0,
valid = s.replace(
/\b\S/g,
function(a) {
e |= a != a.toUpperCase();
}
), !e;


<...>
He then takes advantage of the fact that the comma operator returns the value of the last operand to set -valid- to the negated value of -e-.


Not as given, though -- that will produce a syntax error in the "var"
statement, as "!e" is not an identifier. Bracketing the expression
"(...)" assigned to "valid" should give the intended effect that you
describe.
../rh

Jul 23 '05 #8
rh wrote:
Not as given, though -- that will produce a syntax error in the "var"
statement, as "!e" is not an identifier. Bracketing the expression
"(...)" assigned to "valid" should give the intended effect that you
describe.


Yes, absolutely correct. Disadvantage of copy&pray: Took it from
another piece of code where I had declared "valid" some lines
before and then simply added the comma before "valid = ...".

Corrected:

var s = Element.value,
e = 0,
valid = (s.replace(
/\b\S/g,
function(a) {
e |= a != a.toUpperCase();
}
), !e);
ciao, dhgm
Jul 23 '05 #9
JRS: In article <zG*******************@twister.nyroc.rr.com>, dated
Wed, 2 Feb 2005 01:04:31, seen in news:comp.lang.javascript, Mick White
<mw***********@rochester.rr.com> posted :

Thanks, Grant, I'll have to investigate the "|" operator


Pray tell me what should be added to
<URL:http://www.merlyn.demon.co.uk/js-logic.htm> !
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #10
Dr John Stockton wrote:
JRS: In article <zG*******************@twister.nyroc.rr.com>, dated
Wed, 2 Feb 2005 01:04:31, seen in news:comp.lang.javascript, Mick White
<mw***********@rochester.rr.com> posted :
Thanks, Grant, I'll have to investigate the "|" operator

Pray tell me what should be added to
<URL:http://www.merlyn.demon.co.uk/js-logic.htm> !

Good stuff, John, the truth table looks like a reverse NOR gate to me
(only false if both inputs are false).

1|0 : 1
1|1 : 1
0|1 : 1
0|0 : 0
Thanks.
Mick

Jul 23 '05 #11
Lee
Mick White said:

Dr John Stockton wrote:
JRS: In article <zG*******************@twister.nyroc.rr.com>, dated
Wed, 2 Feb 2005 01:04:31, seen in news:comp.lang.javascript, Mick White
<mw***********@rochester.rr.com> posted :
Thanks, Grant, I'll have to investigate the "|" operator

Pray tell me what should be added to
<URL:http://www.merlyn.demon.co.uk/js-logic.htm> !

Good stuff, John, the truth table looks like a reverse NOR gate to me
(only false if both inputs are false).

1|0 : 1
1|1 : 1
0|1 : 1
0|0 : 0


A "reverse NOR gate" being, of course, an OR gate.

Jul 23 '05 #12
Lee wrote:
Mick White said:


Good stuff, John, the truth table looks like a reverse NOR gate to me
(only false if both inputs are false).

1|0 : 1
1|1 : 1
0|1 : 1
0|0 : 0

A "reverse NOR gate" being, of course, an OR gate.


Yes of course!!!!
It's been a while since I have worked with SSE.
Mick
Jul 23 '05 #13

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

Similar topics

4
by: Sandman | last post by:
I have a input like this: <select name="born-year"> </select> And I want to set this input to the first in selectedIndex, which usually is done by document.form.input.selectedIndex = 0
2
by: RobG | last post by:
I am creating form elements with names that I'd like to reflect th Dublin Core metadata set, e.g. DC.Date, DC.Subject, etc. However, when I use them with dots, it completely confuses JavaScript...
3
by: larry | last post by:
Hi, I am a newbie to Internet programming. I have some questions about spacing in HTML control names and subsequently being able to access these input elements in JavaScript If you don't have...
1
by: Steve | last post by:
I have looked through the newsgroup for an answer to this but haven't been able to find anything resembling my situation. What I want to do is relatively simple, I think. I have a crosstab...
3
by: Saradhi | last post by:
How to get the names of all the Resources embedded in a Resource File? -SARADHI
10
by: Peter Kirk | last post by:
Hi I am looking at some C# code, and can see in some of the classes there are instance variables whose names start with an underscore, for example: private string _projectId; Is there a...
12
by: ross | last post by:
The following gives an error: <?php $super-man=100; ?> Parse error: parse error, unexpected '=' in /test.php on line 2 I understand that the "-" sign is seen as an operator. is there a...
3
by: MLH | last post by:
Generally, I do not monkey with renaming controls on forms whose name, by default, matches the name of their related table fields. But I noticed the following today If IsNull(Me!VColor) Then...
2
by: Agent Michael Scarn | last post by:
Hello, I need to be able to dynamically display all of the form names from a form I just submitted. I have a javascript which will display all the names of the form on the first page, but i...
9
by: dhtml | last post by:
I have written an article "Unsafe Names for HTML Form Controls". <URL: http://jibbering.com/faq/names/ > I would appreciate any reviews, technical or otherwise. Garrett --...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.