working with JavaScript replace method

Hi experts,

I have this fiddle example:
https://jsfiddle.net/n5ydqwyx/1/

I have a text box on my page.
When I type in the textbox, anytime I type a comma, the comma gets replaced with a comma plus a space
Only time that a space is not put after a comma is when it's followed by an equal sign.

For example when i type in the textbox ,everytime I typed a comma it put a space right after it like this:
CommaSDeletesCharacter.PNG
There is one issue though. The character that I typed right after the comma gets deleted.

For example if I type  ,m then that gets replaced with comma and a space so it looks like this:

m.PNG
Any character that I typed right after the comma should not get deleted.

For example if I type ,p then it should display a comma then a space then a p after the space like this:

, p

For example, if I typed this in the textbox:

MTKE,KL,TEHRT,W

I should get this:

MTKE, KL, TEHRT, W

But I'm getting this:

n.PNG
It's deleting the first character that I typed after each comma.



Anyone know How I can fix my fiddle?
LVL 1
maqskywalkerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Try this
 this.value = this.value.replace(/,([^\= ])/g, ', $1');

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
maqskywalkerAuthor Commented:
Really nice! Thanks!
0
Julian HansenCommented:
You are welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.