custom fields (#744)

---------

Co-authored-by: Carlos Valente <carlosvalente@pm.me>
This commit is contained in:
Alex Christoffer Rasmussen
2024-02-17 21:55:46 +01:00
committed by GitHub
parent 1a420a1ddd
commit c1377544a0
17 changed files with 347 additions and 6 deletions
@@ -0,0 +1,17 @@
import { isAlphanumeric } from './isAlphanumeric';
describe('test isAlphanumeric() function', () => {
it('it OK strings', () => {
const ts = ['abcdefghijklmnopqrstuvwxyz', '0123456798', '123asd'];
for (const s of ts) {
expect(isAlphanumeric(s)).toBe(true);
}
});
it('it bad strings', () => {
const ts = ['!abcd1234', 'åøæ', '*'];
for (const s of ts) {
expect(isAlphanumeric(s)).toBe(false);
}
});
});
@@ -0,0 +1,8 @@
/**
* @description Validates a alphanumeric string
* @returns {boolean}
*/
export const isAlphanumeric = (text: string): boolean => {
const regex = /^[a-z0-9]+$/i;
return regex.test(text);
};