简体   繁体   English

如何检查字符串的第一个字符是否是数字作为 *ngIf 中的条件

[英]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.

相关问题 如何为字符串的第一个字符设置样式? - How can I style the first character of a string? 如何检查字符串中的最后一个字符? - How can I check the last character in a string? 如何检查字符串是否为有效数字? - How can I check if a string is a valid number? 检查第一个字符串 - Check First Character String 如何识别字符串中的第一个字符是否是Javascript中的数字 - How to identify if first character in a string is a number in Javascript 如何检查字符串的字符是否已经是数组的元素? - How can I check if a character of a string is already a element of an array? 如何检查字符串是否包含至少一个数字,字母和既不是数字也不是字母的字符? - How do I check if a string contains at least one number, letter, and character that is neither a number or letter? 如何检查字符串中的第一个字符以及如何将该字符串发送到 Jquery 中的数组中? - How to check first character in string and how to send that string into an array in Jquery? 如何在ngIF条件下检查object是null还是在angular中未定义 - how to check if object is null or undefined in angular in ngIF condition 如何使用javascript检查文本框中的第一个字符是否为数字? - how to use javascript to check if the first character in a textbox is a number?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM