Jump to content

Comprendre la validation du formulaire d'inscription standard


 Share

Recommended Posts

Bonjour à tous, 

 

j'aimerais comprendre la validation du formulaire en standard.

 

J'ai par exemple en champ Iban ici a vérifier.

J'ai donc placé en override dans Customer.php :

'swift' => array('type' => self::TYPE_STRING, 'validate' => 'isSwift', 'required' => true)   

 

et j'ai ajouté, tjs en override,  

 

public static function isSwift($value)
    {
if(!eregi("^([a-zA-Z]){4}([a-zA-Z]){2}([0-9a-zA-Z]){2}([0-9a-zA-Z]{3})?$", $value)) 
{
return false;
}
else 
{
return true;
}
        return false;
    }

Ca fonctionne bien, ma question, est la suivante, comment faire en sorte de faire cette vérification à la sortie de ce champ ? 

J'ai bien essayé certaines choses dans validate.js mais je n'y parvient pas....

d'après ce que je comprend, il faudrait ajouter une fonction comme celle-ci : 

function validate_isSwift(s)
{
	return true;
}

avec forcément le bon code dedans.. mais que je renvoie vrai ou faux... pas de résultat ...

 

code de mon TPL

<input type="text" class="is_required validate form-control" data-validate="isFullFilled" name="swift" id="swift" value="{if isset($smarty.post.swift)}{$smarty.post.swift}{/if}"/>

Une idée ? 

 

Merci :-)

 

Share this post


Link to post
Share on other sites

Bon, trouvé, pour ceux que ça interresse pour l'iban  : 

function validate_isIban(s)
{
	var result = isValidIBANNumber(s)
	if(result==1)
	{ 
		return true;
	}
	else
	{
		return false;
	}
}

function isValidIBANNumber(input) 
{
    var CODE_LENGTHS = {
        AD: 24, AE: 23, AT: 20, AZ: 28, BA: 20, BE: 16, BG: 22, BH: 22, BR: 29,
        CH: 21, CR: 21, CY: 28, CZ: 24, DE: 22, DK: 18, DO: 28, EE: 20, ES: 24,
        FI: 18, FO: 18, FR: 27, GB: 22, GI: 23, GL: 18, GR: 27, GT: 28, HR: 21,
        HU: 28, IE: 22, IL: 23, IS: 26, IT: 27, JO: 30, KW: 30, KZ: 20, LB: 28,
        LI: 21, LT: 20, LU: 20, LV: 21, MC: 27, MD: 24, ME: 22, MK: 19, MR: 27,
        MT: 31, MU: 30, NL: 18, NO: 15, PK: 24, PL: 28, PS: 29, PT: 25, QA: 29,
        RO: 24, RS: 22, SA: 24, SE: 24, SI: 19, SK: 24, SM: 27, TN: 24, TR: 26
    };
    var iban = String(input).toUpperCase().replace(/[^A-Z0-9]/g, ''), // keep only alphanumeric characters
            code = iban.match(/^([A-Z]{2})(\d{2})([A-Z\d]+)$/), // match and capture (1) the country code, (2) the check digits, and (3) the rest
            digits;
    // check syntax and length
    if (!code || iban.length !== CODE_LENGTHS[code[1]]) {
        return false;
    }
    // rearrange country code and check digits, and convert chars to ints
    digits = (code[3] + code[1] + code[2]).replace(/[A-Z]/g, function (letter) {
        return letter.charCodeAt(0) - 55;
    });
    // final check
    return mod97(digits);
}

function mod97(string) {
    var checksum = string.slice(0, 2), fragment;
    for (var offset = 2; offset < string.length; offset += 7) {
        fragment = String(checksum) + string.substring(offset, offset + 7);
        checksum = parseInt(fragment, 10) % 97;
    }
    return checksum;
}

et dans le formulaire ne pas oublier 

data-validate="isIban"

 

:-)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More