表格中的姓名 [英] Names in forms

查看:63
本文介绍了表格中的姓名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


如何使用正则表达式检查表单字段中的名称

是否以大写字母开头?

Hi there,

How can I use a regular expression to check that a name in a form field
begins with a capital letter?

推荐答案

Steve Darby写道:
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 startsWithCap = /^[AZ]/.test(Element.name);


因为这不包括é,?等我宁愿用


var firstChar = Element.name.charAt(0),

startsWithCap = firstChar.toUpperCase()== firstChar;


ciao,dhgm



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:文章< 36 ********* ****@individual.net> ;,日期:1月29日星期六

2005 21:47:28,见于新闻:comp.lang.javascript,Dietmar Meier

<我们*************** @ innoline-systemtechnik.de>发表:
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写道:
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 startsWithCap = /^[AZ]/.test(Element.name);

由于这不包括é, ;?"等我宁愿用

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



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;




OP写了一个名字;该字段可能包含类似dietmar

meier的内容,在这种情况下需要进行两次检查。


他可能需要比那;姓氏包括诸如O'B $ b O'Brien,McCarthy,Chomondeley-Featherstonehaugh和适当等姓氏。姓名

包括教皇格雷戈里十三世。


-

?约翰斯托克顿,英国萨里。 ?@merlyn.demon.co.uk Turnpike v4.00 MIME。 ?

Web< URL:http://www.merlyn.demon.co.uk/> - w。常见问题主题,链接,首字母缩略词

PAS EXE等:< URL:http://www.merlyn.demon.co.uk/programs/> - 见00index.htm

日期 - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm等



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.


John Stockton博士写道:
Dr John Stockton wrote:
OP写了一个名字;该字段可能包含类似dietmar
meier的内容,在这种情况下,需要进行两次检查。


如果是这种情况,我会建议


var s = Element.value,

e = 0,

有效= s.replace(

/ \ b\S / g,

函数(a){

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

}

),!e;

他可能需要更加小心;姓氏包括诸如O'Brien,McCarthy,Chomondeley-Featherstonehaugh和适当等姓氏。姓名
包括教皇Gregory XIII。
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.




另一方面,Piet van der Falk,Karl von und zum Stein,等等。
应被视为有效名称。


ciao,dhgm



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

ciao, dhgm


这篇关于表格中的姓名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆