Validating on a line by line basis
I'm looking to validate text in a text-area based on several regex patterns on a line by line basis. What's the best way to approach this? The way I've thought of is to use the the .change() event and split the text at line break characters. Then looping over each line and checking validity. This a开发者_Python百科pproach seems quite wasteful though, is there a more efficient way?
Probably you're not using ASP.Net, but if you would, you could use data annotations, create a that rule and place it above the textarea corresponding property. That same exact and centralized rule will work for client and server side.
If, by any chance, you can use data annotations, do it. Otherwise, you can use the method you described using the change event. You could also use the blur method or, even if you use change, only execute the validation test if the last key inserted was enter. This way, you could at least save some client resources.
精彩评论