I guess it is legal , depending on how the weather is outside. If it's too cold or too hot , people can call police and they'll break into your car to save your dog. Also , I can't begin to tell you how many times we hear about distressed pet owners who get their car stolen , and never see their dogs again.
IMO , not a good idea to leave a pet so long in a car.