Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function typeValidation(type) {
- if (!(/[A-Za-z0-9]{1,}$/i.test(type)) || type === '' || typeof (type) !== 'string') {
- throw new Error('Only Latin letters and digits and must not be an empty string!');
- }
- }
- function attributeValidation(name) {
- if (!(/^[A-Za-z0-9-]{1,}$/i).test(name)) {
- throw new Error('only Latin letters, digits or dashes and must not be an empty string!');
- }
- }
- function childValidation(child) {
- if (typeof (child) !== 'string' && Object.getPrototypeOf(child) !== domElement) {
- throw new Error('Child must be either string or a domElement');
- }
- }
- function parentValidation(parent) {
- if (Object.getPrototypeOf(parent) !== domElement) {
- throw new Error('Parent must be a domElement.');
- }
- }
- function contentValidation(content) {
- if (typeof (content) !== 'string') {
- throw new Error('Content must be a string.');
- }
- }
- function getSortedAttributes(attributes) {
- var attributesAsArray = [];
- for (var prop in attributes) {
- if (attributes.hasOwnProperty(prop)) {
- attributesAsArray.push(prop)
- }
- }
- attributesAsArray = attributesAsArray.sort();
- return attributesAsArray;
- }
- function isValidISBN(ISBN) {
- var regex = /^[0-9]{10,13}$/;
- return regex.test(ISBN);
- }
- function isEmpty(obj) {
- for (var key in obj) {
- if (obj.hasOwnProperty(key)) {
- return false;
- }
- }
- return true;
- }
- function isEmpty(str) {
- return (!str || 0 === str.length);
- }
- function parseBoolean(value) {
- switch (value) {
- case "true":
- return true;
- case "false":
- return false;
- default:
- throw new Error("Invalid boolean value: " + value);
- }
- }
- function isInteger(x) {
- return ((x ^ 0) === x);
- }
- //Валидно ID - ако се подава цяло като стринг и трябва да мине, да се слага eval(числото)
- function isValidID(x) {
- if (!isNaN(x) && ((x ^ 0) === x) && x > 0) {
- return true;
- }
- return false;
- }
- //Заглавие без последователни интервали, не започва и не завършва с интервал и има поне една буква
- function isValidTitle(x) {
- if (typeof (x) === 'undefined') {
- return false;
- }
- if (x.length <=1|| (x !== x.trim()) || x.match(/\s{2,}/)) {
- return false;
- }
- return true;
- }
- //валидно име интервал между името и фамилията, първо име и второ име започват с главна буква
- function isNameValid(name) {
- var nameArray;
- if (typeof name !== 'string') {
- return false;
- }
- nameArray = name.split(' ');
- if (nameArray.length !== 2) {
- return false;
- }
- if (nameArray.some(function(item) {
- if (item.length > 1) {
- return !(/[A-Z]/.test(item[0]) && /^[a-z]/.test(item.substring(1)));
- } else {
- return !(/[A-Z]/.test(item));
- }
- })) {
- return false;
- }
- return true;
- }
- //Проверката на Дончо
- var CONSTS = {
- PLAYER: {
- MIN_LENGTH: 3,
- MAX_LENGTH: 30
- }
- },
- validNameCharacters = 'qwertyuiopasdfghjklzxcvbnm' + 'qwertyuiopasdfghjklzxcvbnm'.toUpperCase() + ' \'"-_.,1234567890!*',
- players,
- playlists;
- function isNameValid(name, min, max) {
- var result = typeof (name) === 'string' &&
- min <= name.length && name.length <= max &&
- name.split('').every(function (ch) {
- return validNameCharacters.indexOf(ch) >= 0;
- });
- return result;
- }
- //има ли такъв елемент
- function indexOfElementWithIdInCollection(collection, id) {
- var i, len;
- for (i = 0, len = collection.length; i < len; i++) {
- if (collection[i].id == id) {
- return i;
- }
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement