我很難用正則表達式。任何幫助將不勝感激。ng-pattern(regex)來驗證驅動器號
問題:我想在用戶在路徑中輸入驅動器號時顯示錯誤。
例如:如果用戶輸入C:\或D:\或S:\ ....表單應該顯示錯誤。 如果有人輸入// remote server/example.txt,應該允許他們繼續。
http://plnkr.co/edit/jyKfOdnctnhCkIeT4r2Z?p=preview
<form name='myform'>
<input type="text" name='ip' ng-model="usd" ng-pattern="/^[a-zA-Z]:*$/"
ng-change="convert_to_btc()" placeholder="Enter path"/>
我認爲你需要'NG-模式的開始=「/ ^(?![A-ZA- Z]:\\)/「',查看[this plunkr](http://plnkr.co/edit/3UcFZNsjxPkVXkUJizu2?p=preview)。如果您不僅需要在字符串的開始處禁止它:'ng-pattern =「/ ^(?!。* \ b [a-zA-Z]:\\)/」' –