SharePoint - Custom Input Validator
npm install @creativeacer/spnamevalidatorbash
npm i @creativeacer/spnamevalidator
`
$3
include the libary
TS
`bash
import SPNameValidator, { Platform, ValidationType } from '@creativeacer/spnamevalidator/SPNameValidator';
`
JS
`bash
var SPNameValidator = require('@creativeacer/spnamevalidator/SPNameValidator').default;
var Platform = require('@creativeacer/spnamevalidator/SPNameValidator').Platform;
var ValidationType = require('@creativeacer/spnamevalidator/SPNameValidator').ValidationType;
`
#### Standard SharePoint illegal char and word list
choose your SharePoint version
`bash
let spNameValidator = new SPNameValidator(Platform["SharePoint 2013 - 2016"]);
or
let spNameValidator = new SPNameValidator(Platform["SharePoint Online"]);
`
#### Using checkName function!
DEFAULT - perform a check on a name / entry
`bash
this.spNameValidator.checkName(string, ValidationType["File - Folder"]);
or
this.spNameValidator.checkName(string, ValidationType["ListName"]);
or
this.spNameValidator.checkName(string, ValidationType["Site"]);
`
This check will use the Default microsoft characters and words
When the string is valid true will be returned.
#### Custom illegal char and word list
If you would like to use a custom character or wordset you can do this by setting the desired illegal characters or words:
`bash
let customSPNameValidator = new SPNameValidator(Platform["SharePoint 2013 - 2016"]);
or
let customSPNameValidator = new SPNameValidator(Platform["SharePoint Online"]);
// Set the characters and words
this.customSPNameValidator.setIllegalCharset(['a', '#', '7']);
this.customSPNameValidator.setIllegalWordset(['One', 'Work', 'Just']);
`
Characters are Case sensitive!
during validation: w !== W
words will be transformerd to uppercase
during validation: Word === WORD
#### Using checkCustomValue function!
CUSTOM
without the default microsoft defined char and words
`bash
this.spNameValidator.checkCustomValue(string, ValidationType["File - Folder"]);
or
this.spNameValidator.checkCustomValue(string, ValidationType["ListName"]);
or
this.spNameValidator.checkCustomValue(string, ValidationType["Site"]);
`
BOTH
or with the default microsoft defined char and words -
add true as third parameter
`bash
this.spNameValidator.checkCustomValue(string, ValidationType["File - Folder"], true);
or
this.spNameValidator.checkCustomValue(string, ValidationType["ListName"], true);
or
this.spNameValidator.checkCustomValue(string, ValidationType["Site"], true);
`
When the string is valid true will be returned.
#### Example test for Runkit
`bash
var SPNameValidator = require('@creativeacer/spnamevalidator/SPNameValidator').default;
var Platform = require('@creativeacer/spnamevalidator/SPNameValidator').Platform;
var ValidationType = require('@creativeacer/spnamevalidator/SPNameValidator').ValidationType;
var validator = new SPNameValidator(Platform['SharePoint 2013 - 2016']);
// should return false
var result = validator.checkName('_test', ValidationType['File - Folder']);
console.log('_test ' + result);
// should return true
var result = validator.checkName('test', ValidationType['File - Folder']);
console.log('test ' + result);
``