0

I have an issue with the way WordPress handles creating a page anchor. The page anchor button is already defined in the WordPress TinyMCE code.. and can be added using either the Ultimate Tinymce or the TinyMCE Advanced plugin.

When clicking the page anchor button, a popup opens asking the name of anchor to be defined.

If entering all letters (myAnchor), everything works as expected.

If entering letters and numbers, beginning with a letter (myAnchor123), it works as expected.

But when entering an anchor beginning with a number (123myAnchor)... an error is thrown.

Here is the code from the WordPress file wp-includes/js/tinymce/themes/advanced/js/anchor.js:

if (!name || !/^[a-z][a-z0-9\-\_:\.]*$/i.test(name)) {
    tinyMCEPopup.alert('advanced_dlg.anchor_invalid');
    return;
}

I am terrible with the regEx function. What I would like to do, is to keep the current functionality, but also add the ability to add anchors which begin with a number.

Any suggestions on how the new regEx should appear?

Thank you so much!

0

I was able to answer my own question. Simply adding a 0-9 into the code above remedied the situation.

Here is the final code:

if (!name || !/^[a-z0-9][a-z0-9\-\_:\.]*$/i.test(name)) {
    tinyMCEPopup.alert('advanced_dlg.anchor_invalid');
    return;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.