Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

First char or first 2 chars !IsNumeric: HELP!

(0) ShareShare
ReportReport
Posted on by 26

Dear all,

i'm in trouble with a simple function where i need to apply an IF based on the follow conditions:

 

IF 1st char is numeric -> write string as is   (123456789 -> 123456789)

IF 1st and 2nd chars are NOT numerics -> write string as is   (ab123456 -> ab123456)

IF 1st char is NOT numeric and 2nd char is numerics -> write string without 1st char   (a123456 -> 123456)

 

I know that i have to use IF, IsNumeric, Left, Right, Len but i missed myself...

 

  • 1000ghz Profile Picture
    1000ghz 26 on at
    Re: First char or first 2 chars !IsNumeric: HELP!

    Thnx @not_a_thing,

    "MID" function instead of "Left" in the second condition solved my problem! 😎

  • Verified answer
    not_a_thing Profile Picture
    not_a_thing 65 on at
    Re: First char or first 2 chars !IsNumeric: HELP!

    You are right, there's an error in the code. Substitute this code

    !IsNumeric(Left(yourText,2))

    With this

    !IsNumeric(Mid(yourText,2,1))

    Left(string, 2) take the both 2 chars from the left. Mid(string, 2, 1) will take 1 char starting from 2nd char.

  • ganeshsanap Profile Picture
    ganeshsanap 1,551 on at
    Re: First char or first 2 chars !IsNumeric: HELP!

    @1000ghz Try something like this: 

     

    If(
    	IsNumeric(Left(TextInput.Text, 1)) || !IsNumeric(Left(TextInput.Text, 2)), TextInput.Text,
    	!IsNumeric(Left(TextInput.Text, 1)), Right(TextInput.Text, Len(TextInput.Text) - 1)
    )

     


    Please click Accept as solution & ‌‌👍 if my answer helped you to solve your issue. This will help others to find the correct solution easily. If the answer was useful in other ways, please consider giving it ‌‌👍

     

    Best Regards,

    Ganesh Sanap

    Blog site 

  • 1000ghz Profile Picture
    1000ghz 26 on at
    Re: First char or first 2 chars !IsNumeric: HELP!

    Hi @not_a_thing and @CNT thank you so much for help but no all conditions are satisfied with your codes.

    In particular when i have 1st and 2nd not numeric char like in the examples below.

    What's wrong?

     

    ✔️ IF 1st char is numeric -> write string as is   (123456789 -> 123456789)  

    123456.JPG

     

     

     

     

     

     

     

     

     

     

     

     

     

    ✔️  IF 1st char is NOT numeric and 2nd char is numerics -> write string without 1st char   (a123456 -> 123456)

    a123456.JPG

     

     

     

     

     

     

     

     

     

     

     

     

     

    ✖️  IF 1st and 2nd chars are NOT numerics -> write string as is   (ab123456 -> ab123456)

    ab123456.JPG

  • not_a_thing Profile Picture
    not_a_thing 65 on at
    Re: First char or first 2 chars !IsNumeric: HELP!

    @CNThas provided a solution that should work, but what you basically have is only 1 condition for string modification: remove first char if it's not numeric, when at the same time the 2nd char is numeric. So:

    If(!IsNumeric(Left(yourText,1)) && IsNumeric(Left(yourText,2)), Right(yourText,Len(yourText)-1), yourText)

    same thing, only shorter

  • CNT Profile Picture
    CNT 10,919 on at
    Re: First char or first 2 chars !IsNumeric: HELP!

    @1000ghz

    Try this,

    If(IsNumeric(Left(yourText,1)) || !IsNumeric(Left(yourText,2)) ,yourText,
     If(!IsNumeric(Left(yourText,1)), Right(yourText,Len(yourText)-1)))

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,526

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,907

Leaderboard