1

My jquery code is now starting to create some pretty long lines of code espically with some of the regex strings. What is the best way to wrap lines of code within your Jquery syntax so that it is easier to read ?

Thanks,

1
  • Could you post some examples? There is no "jQuery syntax" it's JavaScript Syntax Commented Jun 7, 2012 at 13:05

1 Answer 1

2

When dealing with strings you can use concatenation (+) or the backslash (\):

http://www.developfortheweb.com/2009/03/multi-line-strings-in-javascript/

For RegExp you can create them as objects, but you'll need to escape all backslashes.

var REGEX = new RegExp("^\\/[0-9]{1,2}$|^255\\.255\\.255\\.0$");

http://www.regular-expressions.info/javascript.html

Sign up to request clarification or add additional context in comments.

1 Comment

This is great but doesnt seem to work so well for regex strings such as $("#input6").blur(function() { var REGEX = /^\/[0-9]{1,2}$|^255\.255\.255\.0$/;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.