cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rohitsekar1996
Helper I
Helper I

Auto (Slash) add in input field

Hi All,

I have been trying to create a user form. I have a field named "Valid to" were user will be typing date in (mm/dd/yyy) format and I have some other conditions so I cant use Date picker . My query is when user typing date I need to auto populate slash(/) between the mm/dd/yyy is it possible to add slash between intervals so user don't have to add slash manually.

1 ACCEPTED SOLUTION

Accepted Solutions

I like where @eka24 is going with the IsMatch Regex, and I think we can extend that to actually insert the slashes when the format matches one of two correct formats.

 

So keep the Text colour setting @eka24 suggested, this will notify the user when the format they've entered is incorrect, but only if it matches ##-##-####, so we can extend that to include ######## and ##/##/#### as well:

If(
   IsMatch( Self.Text, "\d{2}-\d{2}-\d{4}" )
   ||
   IsMatch( Self.Text, "\d{2}\d{2}\d{4}"
   ||
   IsMatch( Self.Text, "\d{2}\/\d{2}\/\d{4}" )
   ,White,Red
)

 

Then in your control's Default, set it to DateValidated

(a variable we will shortly set via the OnChange)

 

in your control's OnChange, have it do the following:

If(
   IsMatch(Self.Text), "\d{2}-\d{2}-\d{4}",
   Set(DateValidated,
       Left(Self.Text,2) & "/"
      & Mid(Self.Text,4,2) & "/"
      & Mid(Self.Text,7,4)
   ),
   IsMatch(Self.Text), "\d{2}\d{2}\d{4}",
   Set(DateValidated,
       Left(Self.Text,2) & "/"
      & Mid(Self.Text,3,2) & "/"
      & Mid(Self.Text,5,4)
   )
)

 

What the above does is adds in the text slashes to either 01032020 or to 01-03-2020 if it matches those patterns 🙂

 

Hope this helps!

 

Cheers,

Sancho

@iAm_ManCat


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


View solution in original post

2 REPLIES 2
eka24
Super User
Super User

What about letting User select a DatePicker and the results or what has been selected Automatically populate the Textbox?

 

In the Default of the Textbox;

DatePicker1.SelectedDate

Format the DatePicker to "mm/dd/yyyy"

 

If that's not ok try validating the Textbox using the Fill color;

If(IsMatch( "11/11/1111", "\d{2}-\d{2}-\d{4}" ),White,Red)

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

I like where @eka24 is going with the IsMatch Regex, and I think we can extend that to actually insert the slashes when the format matches one of two correct formats.

 

So keep the Text colour setting @eka24 suggested, this will notify the user when the format they've entered is incorrect, but only if it matches ##-##-####, so we can extend that to include ######## and ##/##/#### as well:

If(
   IsMatch( Self.Text, "\d{2}-\d{2}-\d{4}" )
   ||
   IsMatch( Self.Text, "\d{2}\d{2}\d{4}"
   ||
   IsMatch( Self.Text, "\d{2}\/\d{2}\/\d{4}" )
   ,White,Red
)

 

Then in your control's Default, set it to DateValidated

(a variable we will shortly set via the OnChange)

 

in your control's OnChange, have it do the following:

If(
   IsMatch(Self.Text), "\d{2}-\d{2}-\d{4}",
   Set(DateValidated,
       Left(Self.Text,2) & "/"
      & Mid(Self.Text,4,2) & "/"
      & Mid(Self.Text,7,4)
   ),
   IsMatch(Self.Text), "\d{2}\d{2}\d{4}",
   Set(DateValidated,
       Left(Self.Text,2) & "/"
      & Mid(Self.Text,3,2) & "/"
      & Mid(Self.Text,5,4)
   )
)

 

What the above does is adds in the text slashes to either 01032020 or to 01-03-2020 if it matches those patterns 🙂

 

Hope this helps!

 

Cheers,

Sancho

@iAm_ManCat


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (2,457)