Hi there,
How can I use a regular expression to check that a name in a form field
begins with a capital letter? 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
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.
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
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
"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
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
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
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
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.
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
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.
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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
|
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...
|
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...
|
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...
|
by: Saradhi |
last post by:
How to get the names of all the Resources embedded in a Resource File?
-SARADHI
|
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...
|
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...
|
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...
|
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...
|
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
--...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |