As other people have said I think you do have to remember the important thing he has not cheated on you. Ok he has been flirting on line and he is not the first person to do that, nor will he be the last. You do say yourself though that he does not have much self confidence. This may just have been a way for him for him to feel better about himself.
Saying that he has it sounds like you have a lot of talking to do if you do want to save your relationship. You must make it clear how much he has hurt you but make sure you are doing what you want, not what everyone else thinks you should do.
My husband cheated on me after 7 years of marriage and I was devastated as I loved him completely. All my friends told me to throw him out and never take him back. It was difficult at the time but I knew I still loved him. We did a lot of talking and decided to stay together and I have never regretted it. It took a while for the trust to return but 18 years later I know he has never cheated on me again. We have been very happy and are celebrating our 25th anniversary next month.
Just wanted to say things can work out if you do truly love each other but you need to do a lot more talking now and in the future.
Good luck and I hope all works out for you.