I am creating an app that is text to sound translator. And I am using input text from react-native-elements, as well as ternary operators. How do I check if the text input box is empty or has any special characters? The app is supposed to detect this and send an alert.
The following code will show alert when text input is empty and detect special character and show alert, as well as remove the added special character from input
const [inputVal,setInputValue] = React.useState('')
return (
<Input
value={inputVal}
placeholder="Comment"
onChangeText={value => {
if(value==''){
alert('Text Input Empty')
}
let format = /[!"`'#%&,:;<>=@{}~\$\(\)\*\+\/\\\?\[\]\^\|]+/
if(format.test(value)){
alert('Special Character Entered')
let rmvalue = value.slice(0,-1)
setInputValue(rmvalue)
}else setInputValue(value)
}}
/>
);