Disable javascript error display for textbox

173 Views Asked by At
<input name="phone_no" type="text" id="phone_no" maxlength="11">                         
<script type="text/javascript">
    var f1 = new LiveValidation('phone_no');
    f1.add(Validate.Presence,{failureMessage: " It cannot be empty"});
    f1.add(Validate.Format,{pattern: /^[0-9]+$/ ,failureMessage: " It allows only numbers"});
    f1.add( Validate.Length, { minimum: 6, maximum: 11 } );
</script> 

The Javascript is Working but, I need assistance with the following:

  1. How can i make Phone Number optional and not compulsory because the code will not allow empty textbox during registration completion except phone number is provided.
  2. How can I disable the Error prompts when invalid entries are entered and instead the invalid entries be automatically clear and focus retained in that textbox ? Because each time the errors are displayed, the phone No textbox is usually displaced or shifted from its initial position in the form.
  3. In respect of question 2., can the error prompt be transfer for display at the top of the form or elsewhere instead of causing displacement of textbox.
1

There are 1 best solutions below

0
On

For your question 1:

In all your input field declare an attribute mandatory, and check for its value: if it is true consider that or else leave it

<input name="phone_no" type="text" id="phone_no" maxlength="11" mandatory="false">