Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an input field which looks like

 <input class="inputMargin urlInputWidth" type="text" size="40" name="url" ng-model="user.customerId" maxlength="250" ng-pattern="/sftp://.+/" />

It works fine and shows validation as expected. I just wanted to move this pattern to scope of angularjs to get a much neater form. I have tried with this syntax: $scope.sftpValidate="/sftp://.+/"; and ng-pattern="sftpValidate". But this is not validating the pattern at all. i have tried to give as $scope.sftpValidate=/sftp://.+/; and $scope.sftpValidate=sftp://.+;. But these are showing syntax errors. Where am i missing?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Please see JSBin

View:

<input class="inputMargin urlInputWidth" type="text" size="40" name="url" ng-model="user.customerId" maxlength="250" ng-pattern="regex " />

JS

$scope.regex = /sftp://.+/;

JS UPDATED BY sms:

$scope.regex = /sftp:\/\/.+/;
share|improve this answer
1  
For the pattern given in your example its working fine. But for my pattern it is showing syntax expression. Am i missing any escape sequences? –  sms Jun 19 at 9:23
    
you can test your expression here regexr.com –  sylwester Jun 19 at 9:26
1  
I have updated JS in your answer and marked as answer. I have just missed escape char for forward slash. "$scope.regex = /sftp:\/\/.+/;" –  sms Jun 19 at 9:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.