Only allow two special characters and nothing else

vahini
Giga Guru

Hi All, 

 

I have a requirement to create two fields

'Site Title' and

'Provide the custom URL'

Example:

https://theanti.sharepoint.com/sites/YourURL

 

Only special characters permitted are underscore (_) and hyphen (-)  and nothing else is permitted.

 

How to put this restriction in to these two fields ?

 

vahini_0-1739211927471.png

 

Thanks for your time reading this post and responding.

1 REPLY 1

Tony Chatfield1
Kilo Patron

Hi, unfortunately your requirements are not clear in your post.
You state only underscore and hyphen, but then show sample urls including colon and forward slash.

 

Normally you would use an onChange client script containing a regex test to validate your field content.
JavaScript RegExp test() Method

 

Basic syntax

   function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

var regexCheck = /^[a-zA-Z0-9_]+$/;
    if (!regexCheck.test(newValue)) {
       g_form.showFieldMsg("yourField", "Your warning Message", "error");
       g_form.clearValue("yourField);
    }

 

If critical, you might also repeat the regex check in a before insert\update BR to ensure that the data inserted to the DB is always correct.

 

PDI examples of client scripts with regex
/sys_script_client_list.do?sysparm_query=sys_class_name%3Dsys_script_client%5EscriptLIKE.test(&sysparm_view=


If validating a URL you should find some good examples for validating the url content and structure via a google search.
url regex - Google Search