It would seem reasonable on large commercial airlines to require that there be two people in the cockpit at all times. For example when the pilot goes to the toilet a member of the cabin crew must enter the cockpit until the pilot's return. Such a rule would greatly reduce the probability of pilots being locked out and reduce problems should they be locked out. Do any airlines enforce such a rule?
EDIT: please see at the bottom of the answer the update from EASA
Are two people required in cockpit at all times on large commercial aircraft?
From EASA, pag. 101-102: (emphasis mine)
CAT.OP.MPA.210 Crew members at stations
Flight crew members
During take-off and landing each flight crew member required to be on duty in the flight crew compartment shall be at the assigned station.
During all other phases of flight each flight crew member required to be on duty in the flight crew compartment shall remain at the assigned station, unless absence is necessary for the performance of duties in connection with the operation or for physiological needs, provided at least one suitably qualified pilot remains at the controls of the aircraft at all times.
During all phases of flight each flight crew member required to be on duty in the flight crew compartment shall remain alert. If a lack of alertness is encountered, appropriate countermeasures shall be used. If unexpected fatigue is experienced, a controlled rest procedure, organised by the commander, may be used if workload permits. Controlled rest taken in this way shall not be considered to be part of a rest period for purposes of calculating flight time limitations nor used to justify any extension of the duty period.
Do any airlines enforce such a rule?
As other answers mention, yes.
EDIT: On the 27th March 2015 EASA has issued the following Safety Information Bulletin :
operators are recommended to implement procedures requiring at least two persons authorised in accordance with CAT.GEN.MPA.135 to be in the flight crew compartment at all times, or other equivalent mitigating measures to address risks identified by the operator’s revised assessment.
This still does not mean that 2 people are required, but are recommended.
It's not required by a regulation, but, yes, it is required by the procedures of some airlines, at least in the U.S.
A flight attendant taking the seat of an absent pilot to ensure there are always two people in the cockpit, and/or blocking access to the open door with a trolley, are often seen on US flights, but not necessarily on others, Hansford said. For instance it is not a requirement on Australian flights.
I've also heard numerous U.S. airline passengers claim to have witnessed this frequently, though I don't recall having seen it personally.
The FAA has very similar rules about flight crewmembers leaving their station.
(b) A required flight crewmember may leave the assigned duty station—
(1) If the crewmember's absence is necessary for the performance of duties in connection with the operation of the aircraft;
(2) If the crewmember's absence is in connection with physiological needs; or
(3) If the crewmember is taking a rest period, and relief is provided—...
It goes on to describe the requirements of a relief crewmember, but this is only if the pilot is taking a "rest period".
The "Two Crewmember Rule" has been mandatory for all US passenger airlines since 9/11 as well as for all foreign airline flights in and out of the US.The only exceptions are a few very small commuter airlines that fly single-pilot in Cessna 402s and Caravans and Piper Chieftains in remote places like Alaska, Hawaii and the V.I. (and Nantucket!).