If your battery charging light comes on while you're driving, you should pull over as soon as it's safe. This light comes on when your alternator is not making electricity and the car is running off of battery power alone. You can drive a short distance on the battery, especially if you turn off most of your car's electrical items (like the radio, air conditioning, etc.), but there's no way to know how far you'll get before it dies.
If you see this light come on, you'll either need to replace your alternator belt or the alternator, but before you do this, go ahead and check your battery connections. Sometimes cleaning the connections will fix a charging problem.