I need to do dynamic validation on a number while user giving input. Number format should be-- before decimal it should restrict 12 digit and after decimal 2 digit. I have written one validation function using Onkeyup and by giving maxlength. But I am facing issue like, if I remove one digit after decimal then its allowing more than 13 digit before decimal.
below function I have written for validation
function validation(e){ var t = e.value; if( t.indexOf(".") <= 0 ) { e.value = t.substr(0,12); } if( ( t.slice( 0, e.selectionStart ).length >= ( t.indexOf(".") + 3 ) ) { e.value = ( t.indexOf(".") >= 0 ) ? ( t.substr( 0, t.indexOf(".") ) + t.substr( t.indexOf("."), 3 ) ) : t } Appreciate any help!! Thanks.
sliceas it mutates source data). Also this isn't localizable - have you considered usingIntlinstead?<input />element, have you considered usingpattern=""instead? That way you don't need any JavaScript at all.