[英]How can I check if the first character of a string it is a number as a condition in *ngIf
I am trying to check if a document name it is coming with the first char as a number.我正在尝试检查文档名称是否带有第一个字符作为数字。 I am not able to make my code go in and display "Dummy string".我无法让我的代码进入并显示“虚拟字符串”。 I tried with this two options but it is not working.我尝试了这两个选项,但它不起作用。
1.
let documentPDF = "6487954.pdf"
<ng-container *ngIf="Character.isDigit(ParseInt(documentPDF.charAt(0))) == false">
Dummy string
</ng-container>
2.
let document = "6487954.pdf"
<ng-container *ngIf="isNaN(ParseInt(documentPDF.charAt(0))) == false">
Dummy string
</ng-container>
Thank you for your help.谢谢您的帮助。
you can use a regular expression:您可以使用正则表达式:
try this:试试这个:
let documentPDF = "6487954.pdf"
<ng-container *ngIf="!/^\d/.test(documentPDF)">
Dummy string
</ng-container>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.