I am going to add front-end validation for customer attribute by adding CSS classes 'validate-length' and 'maximum-length-xx' in the input tag.

I need to find how I can retrieve, for example, the Maximum Text Length value of customer attribute 'First Name'.



This worked for me for the telephone attribute. I addapted the script for firstname, but please check it again, in case I missed something.

$firstname = Mage::getSingleton('eav/config')->getAttribute('customer', 'firstname');
$rules = $firstname->getValidateRules();
$validationClasses = array();
if (isset($rules['min_text_length'])){
    $validationClasses['validate-length'] = 1;
    $validationClasses['minimum-length-'.$rules['min_text_length']] = 1;
if (isset($rules['max_text_length'])){
    $validationClasses['validate-length'] = 1;
    $validationClasses['maximum-length-'.$rules['max_text_length']] = 1;

$class = implode(' ', array_keys($validationClasses));
//use $class in the form.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.