Regex in Javascript and C# for text validation

Asked

Viewed 41 times

2

In an application Asp.Net WebForms, have a TextBox which I need to validate if it contains any excerpts where there are < followed by any character except blank space.

For example:

Nesse texto pode existir < com espaço. Mas não pode <. <+ <? </ <\ <A <0 <*

In this case, Regex should find eight results = <., <+, <?, </, <\, <A, <0 and <* and not identify < (which contains space).
Where A represents any alphanumeric character and 0 any number.

This Regex will be used in the event onchange() of the HTML page via Javascript and on TextChanged() on the Asp.Net.

Thanks for the help!

  • It’s to detect html?

  • It’s very similar, but the purpose is not exactly this... I found validations for HTML, but I couldn’t adapt for the use I need...

1 answer

2


I do not know if I understood very well, see if this example helps.

<input type="text" id="input_teste" name="input_teste"/>
<input type="submit" value="Testar" onclick="valida_teste()"/>
<script type="text/javascript">
function valida_teste()
{ var filter_test = /< /g;
  if(!filter_test.test(input_teste.value))
  {   alert("O valor : " + input_teste.value + "é incorreto");
  }else
  {   alert("O valor : " + input_teste.value + "é correto");
  }
}
</script>

  • Perfect! That’s right. Thank you Magichat.

  • 1

    Blz... so I got it right, heheh

Browser other questions tagged

You are not signed in. Login or sign up in order to post.