phone_mobile 验证 prestashop

phone_mobile validation prestashop

我正尝试在结帐时在 phone_mobile 字段中的 prestashop 中进行另一次验证。我要做的验证是检测用户在此字段中键入的前 2 个数字。因此,如果不是特定数字 (04),那么如果他试图继续,我想在单击继续订单时显示错误。我怎样才能做到这一点? isPhoneNumber 函数 发生在哪里?我在哪里可以编辑它?

我可以这样做吗:

$(document).ready(function(){
    $('input#phone_mobile').change(function(){

        if($(this).val()!='04'){
        $(this).closest('div').removeClass('form-ok').addClass('form-error');
        }

        });
});

我认为这会出错,但最后如果用户单击继续,他会正常进行,不会出现任何错误。

谢谢!

$(document).ready(function(){
    $('input#phone_mobile').on("input", function(){
        if($(this).val().substring(0,1)!='04') {
           $(this).closest('div').removeClass('form-ok').addClass('form-error');
        }
    });
});

您可以使用子字符串来完成您的要求.. http://www.w3schools.com/jsref/jsref_substring.asp这是教程。