Skip to content

Instantly share code, notes, and snippets.

@rizkytegar
Created February 26, 2024 07:24
Show Gist options
  • Save rizkytegar/a3fef43a7b62386af70c99ac40a55d03 to your computer and use it in GitHub Desktop.
Save rizkytegar/a3fef43a7b62386af70c99ac40a55d03 to your computer and use it in GitHub Desktop.
import 'dart:io';
void main() {
String nama, jenisKelamin, tanggalLahir;
while (true) {
stdout.write('Masukkan nama: ');
nama = stdin.readLineSync()!;
if (nama.isNotEmpty) {
break;
}else{
print("nama wajib di isi!");
}
}
while (true) {
stdout.write('Masukkan jenis kelamin (L/P): ');
jenisKelamin = stdin.readLineSync()?.toUpperCase() ?? '';
if (jenisKelamin == 'L' || jenisKelamin == 'P') {
break;
}else{
print("Jenis Kelamin wajib di isi!");
}
}
RegExp tanggalRegex = RegExp(r'^\d{4}-\d{2}-\d{2}$');
while (true) {
stdout.write('Masukkan tanggal lahir (format: YYYY-MM-DD): ');
tanggalLahir = stdin.readLineSync()!;
if (tanggalRegex.hasMatch(tanggalLahir)) {
break;
}else{
print("masukan tanggal lahir dengan benar, format: YYYY-MM-DD");
}
}
print('\nData yang dimasukkan: \n Nama: $nama \n Jenis Kelamin: ${jenisKelamin == 'L' ? 'Laki-laki' : 'Perempuan'} \n Tanggal Lahir: $tanggalLahir');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment