I Need a custom form validation in a textbox
The value should be like this 3-5, so <number>-<number>
Please suggest me some ideas
I Need a custom form validation in a textbox
The value should be like this 3-5, so <number>-<number>
Please suggest me some ideas
You can create custom Javascript validation for any form. Inchoo has a post about that and Alan Storm also wrote something about it
After the form is initiated in your html, which would look something like var theForm = new VarienForm('theForm', true); add the following
Validation.add('validate-must-be-number-dash-number','Is not number-number!',function(the_field_value){
if(the_field_value.match('/[0-9]-[0-9]/ig'))
{
return true;
}
return false;
});
So, in full; it would look something like this in your form phtml file
<form ... id="theForm">
[...]
<input type="text" class="input-text validate-must-be-number-dash-number" value=""/>
[...]
</form>
<script type="text/javascript">
var theForm = new VarienForm('theForm', true);
Validation.add('validate-must-be-number-dash-number','Is not number-number!',function(the_field_value){
if(the_field_value.match('/[0-9]-[0-9]/ig'))
{
return true;
}
return false;
});
</script>
Now add the class validate-must-be-number-dash-number to your input and you're done
3-5, you can alsways tweak it to check for another value. It's basic javascript, nothing fancy there