Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Minimum length in form field

Guest
Oct 01, 2007 Oct 01, 2007
I am working on a form where a few fields are required. Two of the required fields are work telephone number and home telephone number. I can set a max length for each field but is there anway to set a minimum length for each field so that a user cannot just enter '12' and skip to another field without putting in a complete work extension or home phone number?
2.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 01, 2007 Oct 01, 2007
Will <cfinput message="Please enter a valid Phone Number" name="txt_phone" required="yes" type="text" validate="telephone"> work?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 01, 2007 Oct 01, 2007
I tried that but it will not work for the work phone number since it is only a five digit extension.

Is there a way to do a 'check length'?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Oct 01, 2007 Oct 01, 2007
Javascript.

Phil
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 04, 2008 Jan 04, 2008
LATEST
Can I suggest from a usability perspective that trying to force people to give you information that they don't want to tends to just make the users mad? If you force them to enter 5 digits, they can enter '12345' or '99999' as easily as they enter '12'. If you have a legitimate reason to ask for the phone number, make it clear ("so we can contact you about your request" or whatever).
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 01, 2007 Oct 01, 2007
Thanks Phil but I can't use javascript.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 01, 2007 Oct 01, 2007
MelissaW95 wrote:
> Thanks Phil but I can't use javascript.

can't = do not know how ?
or
can't = not allowed ?

--

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 02, 2007 Oct 02, 2007
I was trying to avoid using javascript but it looks like I have no choice. So, any suggestions on using javascript to require a field to be a certain length?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 03, 2007 Oct 03, 2007
I don't use js often enough to get good at it. I do find google to be my freind though. A good search string would be javascript length.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 03, 2008 Jan 03, 2008
Actually, there is one thing you can do. Editing the cfform.js file will allow you to set a minimum length for all text boxes.

This is what I suggest.

1) Copy all of the files in "/cfide/scripts into a different folder (like /includes/cfscripts) that's not part of the normal CF install
2) Use the "scriptsrc" attribute on the cfform you're working with to point the new folder (scriptsrc="/includes/cfscripts")
3) Open the cfform.js file in your /includes/cfscripts folder and edit the section around line 44 as follows:
if(_c=="TEXT"||_c=="FILE"||_c=="PASSWORD"||_c=="CFTEXTAREA"||_c=="TEXTAREA"||_c=="CFTEXTINPUT"||_c=="DATEFIELD"){
if(_b.value.length<=1){
return false;
}else{
if(_d){
str=_b.value.replace(/^\s+/,"").replace(/\s+$/,"");
if(str.length<=1){
return false;
}
}
}
return true;


That's it. Basically, by changing .length==0 into .length<=1 the length entered in the field must be greater than 2 to "pass".

Please note this change will only affect cfforms with the scriptsrc attribute set to /includes/cfscripts (or whereever you stored your files). All of your other forms will still use the /cfide/scripts/cfform.js version of the validation.

I hope this helps!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 03, 2007 Oct 03, 2007
The only other way is check it once the form has been submitted. That's a good solution, even if you use JavaScript. If it is that important, you should check it even after it has passed the JavaScript and been submitted. Take t from a person who has made that mistake.

It's kind of like the old carpenters adage, "measure once, measure twice, cut". Here you should "check once" with JavaScript then "check twice" once the form has been submitted. Not sure where the "cut" comes into play?

David Moore
UpstateWeb
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 04, 2008 Jan 04, 2008
Sorry Forrest... but it's easier in JavaScript:
1) Set up a js function like this ...
function minium_length_check( ) {
var myForm=document.getElementsByTagName("form"][0];
var myField=myForm.telephone.value;
var minimum = 5;
if (myNbr.length >= minimum) {
return;
} else {
alert( 'Telephone Numbers MUST be at least ' + minimum + ' characters in length!");
myField.focus();
myField.select();
return
}

2) add an "onblur" event to the input field:
<input type="text" name="telephone" size="10" maxlength="16" onblur="javascript:minimum_length_check();" />

... Just be certain to check the length a 2nd time when the data are submitted because the "onblur" event only fires after the viewer gets to - and attempts to leave - the field. But who is to say that they will ever actually visit that field?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources