cancel
Showing results for
Did you mean:
Frequent Visitor

## First char or first 2 chars !IsNumeric: HELP!

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...

1 ACCEPTED SOLUTION

Accepted Solutions

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.

6 REPLIES 6
Super User

@1000ghz

Try this,

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

@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

Frequent Visitor

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)

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

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

Memorable Member

@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

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.

Frequent Visitor

Thnx @not_a_thing,

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

Announcements

#### Celebrating the May Super User of the Month: Laurens Martens

@LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!

#### Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!