The main causes of hospital- and community-acquired urinary tract infections (UTIs) are a group of Escherichia coli (E. coli) strains with multiple virulence factors known as uropathogenic E. coli. One hundred E. coli isolates from the urine specimens of hospital- and community-acquired UTI patients were characterized based on their virulence factors and genetic relatedness using PCR and RAPD‒PCR, respectively. Among all, the traT (71%), sitA (64%), ompT (54%), malX (49%), ibeA (44%), tsh (39%), hlyD (18%) and cnf1 (12%) genes had the highest to lowest frequencies, respectively. There was no significant difference between the frequency of tested virulence genes in E. coli isolates from inpatients and outpatients. The frequency of the hlyD gene was significantly greater in E. coli isolates from patients hospitalized in gynecology, dermatology and intensive care unit (ICU) wards than in those from other wards. Eight virulence gene patterns were common among the isolates of inpatients in different wards of the same hospital, of which five patterns belonged to the isolates of inpatients in the same ward. More E. coli isolates with similar virulence gene patterns and greater genetic similarity were found in female patients than in male patients. The analysis of the RAPD‒PCR dendrograms revealed more genetic similarities among the E. coli isolates from inpatients than among those from outpatients. Our findings indicate the presence of a wide variety of virulence factors in E. coli isolates and the possibility of spreading the same clones in different wards of the hospital.