PDA

View Full Version : how to check min/max amount of characters in a form field


kevin
09-15-2000, 03:29 PM
Hello again,

Thank you for the help on my other question. I have another question, the answer to which I have not been able to accomplish myself, I would like to know how to check how many characters are being submittted in a text input field of a form, the range is between 6 minimum and 10 maximum. I am using a line like this:

if ($Password *here will be the code to check for how many characters*) {&doerror;}

I know I can use the maxlength=10 attribute in the input field, but I would still like the script to double-check that. It needs only check how many characters are in the string, not what type of characters they are. The characters entered can be alpha or numeric, lower or upper case, if that makes any difference. Thank you in advance for any responses.

Kevin

kevin
09-16-2000, 11:18 PM
I think I figured it out. Using this code seems to work OK. Maybe one of you could just confirm this fact for me. Here is the line of code:

if ($Password !~ m/.{6,10}/) {&DoError;}

Thank you,
Kevin

kevin
09-16-2000, 11:36 PM
Well, the above code works fine for the first string value (6) but doesn't return true if the second value (10) is exceeded. Any ideas?

kevin
09-17-2000, 01:36 AM
OK, now I've come up with this:

if (($Password !~ m/.{6,}/) | | ($Password =~ m/.{11,}/)) {&DoError;}

this seems to work to check if the amount of characters entered in the form is between 6 and 10 characters in length. Since there are more than one way to skin a cat using PERL, is there another, more succint way to perform the same task? Am I talking to myself.....:^)

kevin
09-18-2000, 01:27 PM
I guess I am talking to myself. I will unregister myself and not burden this forum with anymore questions.

Jacob
09-18-2000, 04:00 PM
Kevin,

Try the following tweak to your code:

<BLOCKQUOTE><font size="1" face="Verdana, Arial">code:</font><HR><pre>
if ($Password !~ /{6,11}$/) { &DoError; }
[/code]

It's untested, so I'm not sure if it works :)

Regards,

------------------
Jacob A. Wheeler
Co-Founder / Web Engineer
Big Resources Network
jacob@bigresources.com
ICQ: 390147 (http://www.icq.com/390147)

Jacob
09-18-2000, 04:17 PM
Me again,

Try this too:
<BLOCKQUOTE><font size="1" face="Verdana, Arial">code:</font><HR><pre>
if ($Password !~ /^{6,11}$/) { &DoError; }
[/code]

Regards,

------------------
Jacob A. Wheeler
Co-Founder / Web Engineer
Big Resources Network
jacob@bigresources.com
ICQ: 390147 (http://www.icq.com/390147)