Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RegularExpressionValidator

Status
Not open for further replies.

ttrant88

Technical User
Dec 8, 2003
17
0
0
CA
Hi,

I have a name field, which I like to validate, max 50 characters and since it's a name field, so stricly only alpha and space between words are allowed, but I have not so far find away for the space in between the words.

\w{0,50} is about the only thing I know, thanks in advanced for the help (I'm brand new to all these)

TT
 
\s is the pattern for spaces

adding that to the pattern should work fine

_____________________________________________________________________
onpnt2.gif
[sub]
Hakuna matata!!
[/sub]
 
Hello, thanks for teh tip, I did add like you said but no luck, here is what I did \s\w{0,50}
I'm missing something?
TT
 
this says you need a value with a space and then no more then 50 char's

try enclosing the \s in [ ] eg: [\s]

_____________________________________________________________________
onpnt2.gif
[sub]
Hakuna matata!!
[/sub]
 
thinking about it further, you may not want to validate spaces at all. I would suggest getting rid of all the spaces in the value and then testing it. that would take out the occurance of a one word entry. (if that is valid)

although I tested [\s]+\w{0,50} on what I think it is you're trying to validate and it passed fine. maybe it was the alck of the +

_____________________________________________________________________
onpnt2.gif
[sub]
Hakuna matata!!
[/sub]
 
<%
sourcestring=&quot;Some text with spaces&quot;
Set regEx = New RegExp
regEx.Global = True
regEx.IgnoreCase = True
regEx.Pattern = &quot;^[a-zA-Z ]+$&quot;
retVal=regEx.Test(sourcestring)
%>

if retVal=true then it only contains letters and spaces, of course you may want to add in there apostrophes and dashes since they can be in someones name as well

 
Hi

I tried again, as suggested but didn't work.
Actually what I was trying is just the size restriction, a user can key in anything in the text box, and as long as it's under 50 characters, there should be no prompt, may be there are other ways of doing this?

I know of w & W, but don't see any characters that would do both w & W
Thanks very much for the help
TT
 
ttrant88

post a string that is something liek what is a valid entry. then one that is not.

can you also post your function for validating this. sounds like something else it a miss

_____________________________________________________________________
onpnt2.gif
[sub]
Hakuna matata!!
[/sub]
 
If thats all you want then...
<script language=javascript>
function checklen(){
if (document.myform.namebox.value.length>50){alert(&quot;Name must be less than 50 characters&quot;)}
return false;
}
</script>
<form name=myform action=&quot;somepage.asp&quot; onSubmit=&quot;return checklen()&quot;>
<input type=text name=namebox>
<input type=submit>
</form>

 
Thanks Gary...it turns out all I need to do was to use maximum length of the text box! but thanks very much for the help

Tam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top