我想问我如何将我的正则表达式与 if( ( !regex.test( sybol .... , 破折号只能排在第一位,输入只能排一个,点也一样。
$( this ).bind( 'keypress', function( e ){
var code = e.keyCode || e.which;
var symbol = String.fromCharCode( code );
var regex = /[-0-9]|[\b]/;
var currVal = $( this ).val();
var insideInput = currVal.indexOf( '-' );
if( ( !regex.test( symbol ) && code != 37 && code != 39 && code != 46 ) ||
( code == 45 && insideInput == 0 ) || ( currVal.length != 0 && code == 45 ) ) {
e.preventDefault();
}
});