2013-09-27 2 views
0

Reg exps. 내 힘이 아니야. 1-9와 많은 점을 내가 원하는대로 : 입력 지금 내가 할 수있는jQuery - Reg Exp 만 1-9 일에 한 번 포인트

var regex = new RegExp("^[(1-9)(\.)]\d*$"); 

: 여기에 코드를 내 라인입니다. 문제 : 사용자에게 한 점을 정확하게 쓸 수있는 기회 만 제공하고 싶습니다.

어떻게하면됩니까? 여기 내 전체 스크립트입니다 : 어떤 helpin '

답변

0

에 대한

jQuery(document).ready(function($) { 
$('.bet-bit-input').keypress(function (e) { 
      var regex = new RegExp("[(1-9)(\.)]\d*$"); 
      var str = String.fromCharCode(!e.charCode ? e.which : e.charCode); 
      if (regex.test(str)) { 
       return true; 
      } 
      e.preventDefault(); 
      return false; 
    }); 
}); 

감사 ^\d+(\.\d+)?$

+0

. ??? http://jsfiddle.net/DUQsL/ – Issis

0

로 정규식을 교체하는 방법에 대해 :

^[1-9]\d*(?:\.\d+)?$ 

설명 :

^      the beginning of the string 
---------------------------------------------------------------------- 
    [1-9]     any character of: '1' to '9' 
---------------------------------------------------------------------- 
    \d*      digits (0-9) (0 or more times (matching 
          the most amount possible)) 
---------------------------------------------------------------------- 
    (?:      group, but do not capture (optional 
          (matching the most amount possible)): 
---------------------------------------------------------------------- 
    \.      '.' 
---------------------------------------------------------------------- 
    \d+      digits (0-9) (1 or more times (matching 
          the most amount possible)) 
---------------------------------------------------------------------- 
)?      end of grouping 
---------------------------------------------------------------------- 
    $      before an optional \n, and the end of the 
          string 
,451,515,

정규식 ^[(1-9)(\.)]\d*$ 수단 : 작동하지 않습니다

^      the beginning of the string 
---------------------------------------------------------------------- 
    [(1-9)(\.)]    any character of: '(', '1' to '9', ')', 
          '(', '\.', ')' 
---------------------------------------------------------------------- 
    \d*      digits (0-9) (0 or more times (matching 
          the most amount possible)) 
---------------------------------------------------------------------- 
    $      before an optional \n, and the end of the 
          string 
---------------------------------------------------------------------- 
)      end of grouping 
+0

wow thanks man! ;-) – Issis

+0

^[1-9] \ d * (? : \. \ d +)? $이 (가) 나를 위해 작동하지 않습니다. 1-0에서 번호를 입력 할 수 있지만 아무런 의미가 없습니다. 왜? http://jsfiddle.net/6CJzC/ – Issis

+0

@ user2814327 : '아무런 의미가 없습니까?' 지나쳐야 만하는 예제와 실패해야만하는 예제를 줄 수 있습니까? – Toto