简体   繁体   English

javascript获取最后一个非数字字符后的数字

[英]javascript get digits after last non-numeric charachter

I have 3 input in form 我有3个表单输入

<input type="text" name="full" />
<input type="text" name="FilterLeft" />
<input type="text" name="FilterRight" />

When user typing in $(#full), function must be devide value into left side after last non-numeric symbol, and right side after last non-numeric symbol. 当用户键入$(#full)时,必须将函数的值分别指定为最后一个非数字符号后的左侧和最后一个非数字符号后的右侧。 For example, if user typed '6s3f23234' . 例如,如果用户键入'6s3f23234' I want to divide it into $('#FilterLeft').val('6s3f') and $('#FilterRight').val('23234') . 我想把它分成$('#FilterLeft').val('6s3f')$('#FilterRight').val('23234') How to do this? 这个怎么做? thanks. 谢谢。

var str = $('#full').val();
var matches = str.match(/(.*?)([\d]*$)/);

$('#Filterleft').val(matches[1] || '');
$('#FilterRight').val(matches[2] || '');

PS: You should pick one way to name your ids and stick to it. PS:您应该选择一种命名ID并坚持使用的方法。 Either left should be capitalized in Filterleft, or Right should be made lowercase. 左边应该在Filterleft中大写,或者Right应该变成小写。

jsFiddle 的jsfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM