In danger of death, anyone can baptize. It would be valid, but, irregular.
From the Catholic Encyclopedia:
newadvent.org/cathen/02258b.htm
The
Roman Ritual adds that, even in conferring baptism in cases of
necessity, there is an order of preference to be followed as to the
minister. This order is: if a
priest be present, he is to be preferred to a
deacon, a
deacon to a
subdeacon, a
cleric to a
layman, and a man to a
woman, unless modesty should require (as in cases of childbirth) that no other than the
female be the
minister, or again, unless the
female should understand better the method of baptizing. The
Ritual also says that the father or mother should not baptize their own child, except in danger of death when no one else is at hand who could administer the
sacrament. Pastors are also directed by the
Ritual to teach the
faithful, and especially
midwives, the proper method of baptizing. When such private baptism is administered, the other
ceremonies of the
rite are supplied later by a
priest, if the recipient of the
sacrament survives. This
right of any
person whatsoever to baptize in case of
necessity is in accord with the constant
tradition and practice of the
Church.
Tertullian (
7On Baptism) says, speaking of
laymen who have an opportunity to administer baptism: “He will be guilty of the loss of a
soul, if he neglects to confer what he freely can,”
St. Jerome (
9Against the Luciferians): “In case of
necessity, we
know that it is also allowable for a
layman [to baptize]; for as a
person receives, so may he give,” The
Fourth Council of the Lateran (cap. Firmiter)
decrees: “The Sacrament of Baptism . . . no matter by whom conferred is available to
salvation,”
St. Isidore of Seville (can. Romanus de cons., iv) declares: “The
Spirit of God administers the
grace of baptism, although it be a
pagan who does the baptizing,”
Pope Nicholas I teaches the
Bulgarians (Resp. 104) that baptism by a
Jew or a
pagan is valid.