2013-06-05 37 views
-2

我需要填写由“ - ”分隔的文本框两个数字。示例5-3 23-12 如何对这些数字和分隔符一起执行检查(reg exp)?Reg Reg in javascript

<form id="myForm" method="post"> 
<input type="text" name="entered"><br> 
<input type="button" value="Submit" onclick="buttonLogic()"><br> 
<select id="selector"> 
</select> 
</form> 

只需要RegExp的一些帮助。

谢谢!

回答

2

你有一个输入元素,我想。在文本框的值上使用正则表达式。 例如,如果你输入的ID为“盒子”,

var boxValue = document.getElementById('box').value.match(/(\d+)-(\d+)/) 

你会得到与数组: - 箱价值 - 第一个数字 - 第二号

+1

你不应该假设他在使用jQuery,没有提到它在 – naththedeveloper

+0

这个问题上帮了很多!非常感谢你 :) – sla55er

0

你可以试试这个正则表达式:/^(\d+)-(\d+)$/