HackerNewsIndia / Universal

2 stars 0 forks source link

Prevent user from entering special characters. Malicious links in the blog content can be harmful. This needs proper validation requirement. #24

Open athishsreeram opened 1 month ago

athishsreeram commented 1 month ago

image

dinesh9396 commented 1 month ago

how to validate malicious content link ?

dinesh9396 commented 1 month ago

does special characters includes numbers too. (in that case we cant enter numbers in title Example: "Top 10 A.I. courses to learn in 2024").

Plz explain me about this whole issue

athishsreeram commented 2 weeks ago

@dinesh9396

We need to add a validation which will allow just Markdown as input

npm install markdown-it

import React, { useState } from 'react'; import MarkdownIt from 'markdown-it';

const md = new MarkdownIt();

const MarkdownValidator = () => { const [input, setInput] = useState(''); const [isValid, setIsValid] = useState(true); const [error, setError] = useState('');

const handleChange = (e) => { const value = e.target.value; setInput(value);

try {
  // Attempt to parse the input as Markdown
  md.parse(value);
  setIsValid(true);
  setError('');
} catch (err) {
  // If parsing fails, update the state to reflect invalid input
  setIsValid(false);
  setError(err.message);
}

};

return (