meme-generator-nodejs/test-sanitize.js

9 lines
347 B
JavaScript
Raw Normal View History

2023-11-27 16:08:58 +07:00
const sanitizeInput = (text) => {
const allowedCharacters = /^[A-Za-z0-9\s,]$/;
const sanitizedText = text.replace(/[^A-Za-z0-9\s,]/g, '');
return sanitizedText;
};
const input = "<script>alert('Hello, world 123!');</script>";
const sanitizedOutput = sanitizeInput(input);
console.log(sanitizedOutput); // Output: scriptalert(Hello, world!)