1
I have a text field that allows html codes. When the field is empty the tags are passed <p><br></p>
below the screens, if I give several enter in the field below the cloths is inserted several tags <p>
. How can I do a validation to check if the field is empty in this way?
Example: I typed several enter and saved the text, in the backend is shown the value of "<p><br></p><p><br></p><p><br></p>
for the field, however it is empty, I wanted to do a validation so that if there are ONLY HTML tags it means that the field is empty and I cannot allow you to save.
I did the validation:
if (string.IsNullOrEmpty(model.InformacaoObjetivo))
{
ErrorMessage = "Por favor, preencha o campo Texto.";
}
but is not entering if because although the field is empty there are tags that are passing to the field.
It’s not good practice what I’m about to say, but try:
model.InformacaoObjetivo.Substring(model.InformacaoObjetivo.IndexOf('<'), model.InformacaoObjetivo.LastIndexOf('>') + 1).Trim()
. This will cut all tags present in the string– CypherPotato
but I can not cut the tags pq is allowed to use, example if I put there <p> and type a text, have to allow, but when you have only <p> without any text I can not allow ?
– Stand Alone
Change how things work "under the covers", ie, handle before inserting html tags. If the person only gave enter or spaces, instead of inserting <p>... do not enter anything
– Caique Romero