8.1.1 • Published 6 years ago

@creativeacer/spnamevalidator v8.1.1

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

SPNameValidator npm.io npm.io CodeFactor

This validator will help you validate names for SharePoint 2013/2016 or SharePoint Online.
The validation can be used for Lib/list names, file names and Site-Subsite names.

The purpose of this library is to check field inputs by users.
For example if a form is used to create a new list / listItem / ... this code will check if the input is valid for the selected sharepoint version.

DEFAULT - The validator uses the characters and words defined by microsoft as being illegal for both File - Folder - Library - List - Site
Donate

CUSTOM - Next to those you also have the option to set custom characters and words.

BOTH - You also have the option to validate the input on both custom and default characters and words.

I will refer to DEFAULT - CUSTOM - BOTH in the instructions

Donations

If you would like to donate anything, you can always use the following link. Much appreciated! ;)

Donate

Installation

    npm i @creativeacer/spnamevalidator

Usage

include the libary
TS

    import SPNameValidator, { Platform, ValidationType } from '@creativeacer/spnamevalidator/SPNameValidator';

JS

    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

    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

    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:

    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

    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

    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

    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);

Happy coding!

8.1.1

6 years ago

8.1.0

6 years ago

8.0.7

6 years ago

8.0.6

6 years ago

8.0.5

6 years ago

8.0.4

6 years ago

8.0.3

6 years ago

8.0.2

6 years ago

8.0.1

6 years ago

8.0.0

6 years ago

7.2.0

6 years ago

7.1.0

6 years ago

7.0.0

6 years ago

6.0.0

6 years ago

5.0.0

6 years ago

4.0.0

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.5.6

6 years ago

2.5.5

6 years ago

2.5.4

6 years ago

2.5.3

6 years ago

2.5.2

6 years ago

2.5.1

6 years ago

2.5.0

6 years ago

2.0.0

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago