所以我在Xamarin工作,为学校制作一个C#android应用程序,在某些时候用户需要输入一个IBAN号码。 我想检查输入是否等于4次4位数,并在它们之间用短划线(例如1234-1234-1234-1234), 遗憾的是,我不知道该怎么做,到目前为止,我找不到任何可以帮助我的东西。
这是我的活动,我需要检查“mTxtIBAN”的输入是否等于IBAN号码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace LoginSystem
{
[Activity (Label = "SubDetailsBankActivity")]
public class SubDetailsBankActivity : Activity
{
private Button mBtnContinue;
private EditText mTxtIBAN;
private EditText mTxtBIC;
private TextView mIBANWarning;
private TextView mBICWarning;
protected override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);
SetContentView (Resource.Layout.SubBankDetails);
// Create your application here
string email = Intent.GetStringExtra ("Email") ?? "Data not available";
string firstName = Intent.GetStringExtra ("FirstName") ?? "Data not available";
string lastName = Intent.GetStringExtra ("LastName") ?? "Data not available";
string streetNumber = Intent.GetStringExtra ("StreetNumber") ?? "Data not available";
string cityCode = Intent.GetStringExtra ("CityCode") ?? "Data not available";
string country = Intent.GetStringExtra ("Country") ?? "Data not available";
mBtnContinue = FindViewById<Button> (Resource.Id.btnContinue);
mTxtIBAN = FindViewById<EditText> (Resource.Id.IBAN);
mTxtBIC = FindViewById<EditText> (Resource.Id.BIC);
mIBANWarning = FindViewById<TextView> (Resource.Id.IBANtext);
mBICWarning = FindViewById<TextView> (Resource.Id.BICtext);
mBtnContinue.Click += (object sender, System.EventArgs e) =>
{
if (mTxtIBAN.Text.Length != 0 && mTxtBIC.Text.Length != 0) {
var newSub = new Intent(this, typeof(SubDetailsComplete));
newSub.PutExtra ("Email", email);
newSub.PutExtra ("FirstName", firstName);
newSub.PutExtra ("LastName", lastName);
newSub.PutExtra ("StreetNumber", streetNumber);
newSub.PutExtra ("CityCode",cityCode);
newSub.PutExtra ("Country", country);
newSub.PutExtra ("IBAN", mTxtIBAN.Text);
newSub.PutExtra ("BIC", mTxtBIC.Text);
StartActivity (newSub);
}
if (mTxtIBAN.Text.Length == 0){
mIBANWarning.Text = "Fill in your IBAN number!";
}
if (mTxtBIC.Text.Length == 0){
mBICWarning.Text = "Fill in your BIC number!";
}
};
}
}
}
非常感谢任何帮助。 提前谢谢你,祝你有个愉快的一天。
答案 0 :(得分:1)
您可以这样检查:
// turn this
import {Widget} from '../../components';
// into this
import {Widget} from 'components';