Quite a title this time 🙂
Let me explain:
I have a list where people can add items to: requests for a ticket.
Those tickets are ( if approved ) getting into a workflow: every ticket becomes a folder in a list, where we can have actions as list items.
The problem was that my workflow crashes when a forbidden character is used as the name for the new item(item1 “Title” serves as item2 “Name”)
The forbidden SharePoint folder and file name rules are:
o Do not use: ” # % & * : < > ? \ / { | } ~
o File names cannot be longer than 128 characters
o Do not use the period character consecutively in the middle of a file name.
o You cannot use the period character at the end of a file name
o You cannot start a file name with the period character
This code checks for forbidden characters (# % & * : < > ? \ / { | } ~) and removes them on Keyup().
It also checks if the title has more then 128 characters.
I know it is not complete (no check on period as first char and so on), so please bare with me.
function noweirdchars(){ var str = $(":select[title=Title]").val(); var patt = new RegExp( /[#%&*:<>?\/\\{|}~]/m ); $(":select[title=Title]").val(str.replace(patt,"")); if ($(":select[title=Title]").val().length > 128) { alert("Name can only have 128 characters"); event.preventDefault(); } } $(document).ready(function() { $(":input[title='Title']").keyup(function(){ noweirdchars(); }); });