• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1500
  • Last Modified:

Regular Expression

I need this to allow uppercase caps only, with a blank entry required.  

"^[A-Z]{0,1}"

But it seems to give error if the entry field is blank.  

Any suggestions on this would be welcome

Thanks!
0
codequest
Asked:
codequest
2 Solutions
 
stanscott2Commented:
Do it like this:

var str = "";
alert(str.match(/^([A-Z]+)$/)==null);

A true condition means that either a non-caps character is present, or the string is empty.
0
 
netsmithcentralCommented:
Not sure exactly what you need, so here's some for you:

Allow any number of capital letters (or a blank field):
"^[A-Z]*$"

Allow any number of capital letters, no blank field:
"^[A-Z]+$"

Allow exactly one capital letter (or a blank):
"^[A-Z]?$"

Allow exactly one capital letter, no blank field:
"^[A-Z]$"


These last two are NOT available in all flavors of regular expressions.  Javascript allows them, others may or may not.
Allow x capital letters, (or a blank field):
"^[A-Z]{0,x}$"

Allow x capital letters, no blank field:
"^[A-Z]{1,x}$"
0
 
codequestAuthor Commented:
Thanks for inputs, that should do it.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now