webref.eu Posted September 14, 2011 Share Posted September 14, 2011 Hi Guys What code would you use to check that a form field does not exceed 100 characters? Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/247114-code-to-check-form-field-does-not-exceed-100-characters/ Share on other sites More sharing options...
trq Posted September 14, 2011 Share Posted September 14, 2011 strlen Quote Link to comment https://forums.phpfreaks.com/topic/247114-code-to-check-form-field-does-not-exceed-100-characters/#findComment-1269134 Share on other sites More sharing options...
AyKay47 Posted September 14, 2011 Share Posted September 14, 2011 you can use the maxlength attribute with input fields as well..setting a maxlength='100' will ensure that the user can not type in more then 100 characters.. Quote Link to comment https://forums.phpfreaks.com/topic/247114-code-to-check-form-field-does-not-exceed-100-characters/#findComment-1269145 Share on other sites More sharing options...
trq Posted September 14, 2011 Share Posted September 14, 2011 Providing of course they don't bypass your form all together. Quote Link to comment https://forums.phpfreaks.com/topic/247114-code-to-check-form-field-does-not-exceed-100-characters/#findComment-1269150 Share on other sites More sharing options...
Adam Posted September 14, 2011 Share Posted September 14, 2011 Also you can remove max lengths on inputs with the Web Developer add-on (Forms > Remove Maximum Lengths). Quote Link to comment https://forums.phpfreaks.com/topic/247114-code-to-check-form-field-does-not-exceed-100-characters/#findComment-1269151 Share on other sites More sharing options...
AyKay47 Posted September 14, 2011 Share Posted September 14, 2011 right I said you can use the maxlength attribute as well as what thorpe said.. i don't recommend using only that to secure it.. but its there to use so it might as well be allocated as well Quote Link to comment https://forums.phpfreaks.com/topic/247114-code-to-check-form-field-does-not-exceed-100-characters/#findComment-1269152 Share on other sites More sharing options...
Adam Posted September 14, 2011 Share Posted September 14, 2011 Not to pick nits but you put "as well", which suggests an alternative. "As well as" means both. Easy mistake to make both ways though, and if anything will hopefully discourage the OP from ever relying on maxlength. Quote Link to comment https://forums.phpfreaks.com/topic/247114-code-to-check-form-field-does-not-exceed-100-characters/#findComment-1269166 Share on other sites More sharing options...
AyKay47 Posted September 14, 2011 Share Posted September 14, 2011 Not to pick nits but you put "as well", which suggests an alternative. "As well as" means both. Easy mistake to make both ways though, and if anything will hopefully discourage the OP from ever relying on maxlength. sorry if I was unclear there... normally client side security is very unreliable in the first place and I will never encourage using solely that to secure your page... this was simply food for thought.. Quote Link to comment https://forums.phpfreaks.com/topic/247114-code-to-check-form-field-does-not-exceed-100-characters/#findComment-1269172 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.