简体   繁体   English

SFTP URL的正则表达式

[英]Regular Expression for SFTP URL

In my application i am using angularjs and html5. 在我的应用程序中,我正在使用angularjs和html5。 The requirement is to get only sftp sites as URL. 要求是仅将sftp站点作为URL。 The default URL attribute of html5 allows http,https,sftp and ftp sites. html5的默认URL属性允许http,https,sftp和ftp站点。 I think using ng-pattern will solve this issue. 我认为使用ng-pattern将解决此问题。 But i am not sure about the pattern to be used. 但是我不确定要使用的模式。 Can anyone help on this. 任何人都可以帮忙。

<input type="url" name="url" ng-model="user.url" required ng-pattern="sftp://.+"/>
 <span class="error" ng-show="myForm.url.$error.pattern">URL is in Invalid Format
  </span>

The error message for invalid url is not at all displaying. 无效网址的错误消息根本没有显示。

You can use the pattern attribute of the input and write your own regular expression. 您可以使用输入的pattern属性并编写自己的正则表达式。 For example you can accept only strings that starts with sftp and have any following characters. 例如,您只能接受以sftp开头且具有以下任何字符的字符串。 The validation for type="url" will remain and will guarantee that the url is valid. 类型=“ url”的验证将保留,并保证该URL有效。

<input type="url" pattern="sftp://.+" />

The Pattern is correct. 模式是正确的。 Just use ng-pattern="/sftp://.+/" . 只需使用ng-pattern="/sftp://.+/" The // will make the difference. //将有所作为。 The ng-pattern will accept parameters given within /../ braces. ng模式将接受/../大括号内给出的参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM