简体   繁体   中英

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>
    


  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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