如何检查输入值是否与某些正则表达式匹配?

时间:2019-02-15 10:47:09

标签: jquery html regex

有一个问题,在我的代码中,任何字符串始终不匹配。它应该匹配:

Eindhoven, Netherlands
Warsaw, Poland
warsaw, Poland
34234 Ster, USA 

它不应该匹配:

warsaw
warsaw, poland

任何不包含(例如)lowercase[comma][space][uppercase]

的内容

jQuery(document).ready(function($) {
  $('#check').on('click', function() {
    var loc = /^.*\p{Ll}\,\s\p{Lu}.*$/;
    if (!loc.test($('#place').val())) {
      alert('not match');
    } else {
      alert('match')
    }
  })
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="place">
<input type="button" value="check" id="check">
<br><br>
<b>Should match:</b><br> Eindhoven, Netherlands<br> Warsaw, Poland<br>warsaw, Poland<br> 34234 Ster, USA<br><br>
<b style="color:red">Should not match:</b><br><br>warsaw<br>warsaw, poland<br>anything what doesnot contains <b> lowercase[comma][space][uppercase]</b>

我创建了JSfiddle: https://jsfiddle.net/1hnqf5e7/

也是正则表达式: https://regex101.com/r/xWRJAB/2

0 个答案:

没有答案