cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
288088
Post Partisan
Post Partisan

Only allow certain number format in a form textfield

Hello!

 

I got this form where these is a column thats just one line textcolumn. In this field people should only be able to input "yyyy-MM-dd hh:mm:ss" So if someone tries to put in the value "yyyy.MM.dd hh:mm:ss" or "yy_MM_dd hh:mm:ss" it should give a notification warning. Is this possible? 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @288088 ,

 

Apply the if/else logic into Submit button, then the form can only be submitted if the text satisfies validation.

 

SubmitButton.OnSelect:

If(IsMatch(DataCardValue1.Text,"\d{4}-(?:0\d|1[0-2])-(?:[0-2]\d|3[01])( (?:[01]\d|2[0-3])\:[0-5]\d\:[0-5]\d)"),SubmitForm(FormName), Notify("Invalid format"))

 Sik

View solution in original post

5 REPLIES 5
gabibalaban
Super User
Super User

Hi @288088 ,

 

I think you should try IsMatch() function. I think it will work if you set the desired pattern correctly.

 

Hope it helps !

It not a good idea for the users to type that long text into the Textbox. I suggest you rather insert a DatePicker and let them select the Date. Then format the date in the TextBox.

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

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.

v-siky-msft
Community Support
Community Support

Hi @288088 

 

This is more like a Regular Match issue. Please try to set the OnChange property of Text Box as follow:

If(!IsMatch(DataCardValue1.Text,"\d{4}-(?:0\d|1[0-2])-(?:[0-2]\d|3[01])( (?:[01]\d|2[0-3])\:[0-5]\d\:[0-5]\d)"), Notify("Invalid format"))

Snipaste_2020-06-30_15-55-46.png

Hope this helps.

Sik 

@v-siky-msft 

 

Hello! Tried this and it works, it does give the notification but I can still save my form. Is there anyway to prevent that?

Hi @288088 ,

 

Apply the if/else logic into Submit button, then the form can only be submitted if the text satisfies validation.

 

SubmitButton.OnSelect:

If(IsMatch(DataCardValue1.Text,"\d{4}-(?:0\d|1[0-2])-(?:[0-2]\d|3[01])( (?:[01]\d|2[0-3])\:[0-5]\d\:[0-5]\d)"),SubmitForm(FormName), Notify("Invalid format"))

 Sik

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,759)