Try this pattern: @"(?s)^(?!\s*(mailto:|https?:|ftps?:)//)((?!<.*?>).)*$"
.
However, such input limitations should probably not exist.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
[RegularExpression(@"^(\s)|(<.*?>)|(mailto:|http:|https:|ftp:|ftps:|<|\/\/)", ErrorMessageResourceType = typeof(Std), ErrorMessageResourceName = "Validation_WrongFormat")]
[Display(Name = "lbl_Comment", ResourceType = typeof(Resource1))]
[Required(ErrorMessageResourceType = typeof(Std), ErrorMessageResourceName = "Validation_Required")]
public string Comment { get; set; }
Generated on my dotnet 6 web razor page:
<textarea rows="5" style="min-width:100%" data-val="true" data-val-regex="The format is wrong, please modify it and try again." data-val-regex-pattern="^(\s)|(<.*?>)|(mailto:|http:|https:|ftp:|ftps:|<|//)$" data-val-required="The field Comment is required." id="Comment" name="Comment">
</textarea>
The all idea is to not allow any HTML Tag and also no mailto:, https:, etc. string in the textarea control using the regularexpression. Of course the text may have some newline and carriage return.
So far it always returning me an "The format is wrong, please modify it and try again." . I think that the encoding is the issue or something but can't figure this out.
Thanks for the help.
Try this pattern: @"(?s)^(?!\s*(mailto:|https?:|ftps?:)//)((?!<.*?>).)*$"
.
However, such input limitations should probably not exist.
Sorry, it doesn't work as it gives an error on the site:
Uncaught SyntaxError: Invalid regular expression: /(?s)^(?!\s*(mailto:|https?:|ftps?:)//)((?!<.?>).)$/: Invalid group (at jquery.validate.unobtrusive.min.js:5:3856)
Works ok in regex tester like many other but not from the DataAnnotation from my class in C# used on the razor page generated
<textarea asp-for="Comment" rows="5"></textarea>
Also Yes such limitation can be existing as to prevent people to send html code within this text area or unwanted email or html tags :-(
Check an alternative that should work in browsers too: @"^(?!\s*(mailto:|https?:|ftps?:)//)((?!<.*?>)(.|\r|\n))*$"
.
Thank Viorel-1 to direct me to the right direction.
The code provided did not work but close enough so that I found the solution with this version:
@"^((?!<.?>|mailto:|ftps?:|https?:|//|<)(.|\r|\n))$
Thanks again