以magento注册表格进行现场验证

时间:2011-09-13 08:40:32

标签: javascript magento magento-1.5

我正在尝试验证特定域的电子邮件添加的输入字段,并在不满足条件时清除字段的内容。但是输入字段不会使用'onblur'事件清除。这是我的代码:

<input type="text" name="email" onBlur="checkForm();" onSubmit="checkForm()"id="email_address" value="<?php echo $this->htmlEscape($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="input-text validate-email required-entry" />
                        <?php echo "Enter a valid Sonata-software.com E-mail Id"?>

<script type="text/javascript">
    function validateEmail(elementValue){  
       var emailPattern = /^[a-zA-Z0-9._-]+@sonata-software.com$/;  
       return emailPattern.test(elementValue);  
     }  
    function clear(){ 
    document.getElementById("email_address").value = "";
    }
    function checkForm(){
        var emailId = document.getElementById('email_address').value;
        if(! validateEmail(emailId)) {
            alert("Enter a valid Sonata-software.com E-mail Id");
        clear();
                    }   
    }
</script>

1 个答案:

答案 0 :(得分:0)

我只是通过修改两个文件来实现:

  1. /public_html/app/design/frontend/YOURTEMPLATE/default/template/persistent/customer/form/register.phtml(在此处添加了new_class:<input type="text" name="email" id="email_address" value="<?php echo $this->htmlEscape($this->getFormData()->getEmail())? >" title="<?php echo $this->__('Email Address')? >" class="input-text validate-email required-entry new_class" />

  2. /public_html/js/prototype/validation.js(添加了new_class,如下所示:

    ['new_class', 'Only sonata-software.com accounts are allowed.', function (v) {
                return Validation.get('IsEmpty').test(v) || /^[a-zA-Z0-9._-]+@sonata-software.com$/.test(v)
            }],
    
  3. 请告诉我它是否适合你。

相关问题